Chapter 9 Object-Oriented Programming: Inheritance (Web server iis) 375 31 32

Chapter 9 Object-Oriented Programming: Inheritance 375 31 32 // property Radius 33 public double Radius 34 { 35 get 36 { 37 return radius; 38 } 39 40 set 41 { 42 if ( value >= 0 ) 43 radius = value; 44 } 45 46 } // end property Radius 47 48 // calculate Circle5 diameter 49 public double Diameter() 50 { 51 return Radius * 2; 52 } 53 54 // calculate Circle5 circumference 55 public double Circumference() 56 { 57 return Math.PI * Diameter(); 58 } 59 60 // calculate Circle5 area 61 public virtual double Area() 62 { 63 return Math.PI * Math.Pow( Radius, 2 ); 64 } 65 66 // return string representation of Circle5 67 public override string ToString() 68 { 69 // use base reference to return Point3 string 70 return “Center = ” + base.ToString() + 71 “; Radius = ” + Radius; 72 } 73 74 } // end class Circle5 Fig. 9.18 Fig. 9.18Fig. 9.FiFi18g. 9.18g. 9.18Circle5class inherits from class Point3and overrides a finalizer method. (Part 2 of 2.) Notice that the first two lines of the output from this program contain values for the x- y coordinates and the radius of Circle5 object circle1. When constructing a Circle5object, the thisreference used in the body of both the Circle5and Point4 constructors refers to the Circle5 object being constructed. When a program invokes method ToString on an object, the version of ToString that executes is always the version defined in that object s class. Because reference this refers to the current
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