Chapter 9 Object-Oriented Programming: Inheritance 359 protected base-class (Free web servers)

Chapter 9 Object-Oriented Programming: Inheritance 359 protected base-class data members. A derived class also can access protected methods in any of that derived class s base classes. 1 // Fig. 9.10: Circle3.cs 2 // Circle2 class that inherits from class Point2. 3 4 using System; 5 6 // Circle3 class definition inherits from Point2 7 public class Circle3 : Point2 8 { 9 private double radius; // Circle’s radius 10 11 // default constructor 12 public Circle3() 13 { 14 // implicit call to Point constructor occurs here 15 } 16 17 // constructor 18 public Circle3( 19 int xValue, int yValue, double radiusValue ) 20 { 21 // implicit call to Point constructor occurs here 22 x = xValue; 23 y = yValue; 24 Radius = radiusValue; 25 } 26 27 // property Radius 28 public double Radius 29 { 30 get 31 { 32 return radius; 33 } 34 35 set 36 { 37 if ( value >= 0 ) 38 radius = value; 39 } 40 41 } // end property Radius 42 43 // calculate Circle diameter 44 public double Diameter() 45 { 46 return radius * 2; 47 } 48 Fig. 9.10 Fig. 9.10Fig. 9.FiFi10g. 9.10g. 9.10Circle3class that inherits from class Point2. (Part 1 of 2.)
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

Leave a Reply