1 on 1 web hosting - 386 Object-Oriented Programming: Polymorphism Chapter 10 21 Radius

386 Object-Oriented Programming: Polymorphism Chapter 10 21 Radius = radiusValue; 22 } 23 24 // property Radius 25 public double Radius 26 { 27 get 28 { 29 return radius; 30 } 31 32 set 33 { 34 if ( value >= 0 ) // validate radius 35 radius = value; 36 } 37 38 } // end property Radius 39 40 // calculate Circle diameter 41 public double Diameter() 42 { 43 return Radius * 2; 44 } 45 46 // calculate Circle circumference 47 public double Circumference() 48 { 49 return Math.PI * Diameter(); 50 } 51 52 // calculate Circle area 53 public virtual double Area() 54 { 55 return Math.PI * Math.Pow( Radius, 2 ); 56 } 57 58 // return string representation of Circle 59 public override string ToString() 60 { 61 return “Center = ” + base.ToString() + 62 “; Radius = ” + Radius; 63 } 64 65 } // end class Circle Fig. 10.2 Fig. 10.2Fig. 10FiFi.2g. 10.2g. 10.2Circleclass that inherits from class Point. (Part 2 of 2.) Class PointCircleTest (Fig. 10.3) demonstrates assigning derived-class references to base-class references and casting base-class references to derived-class references. Lines 13 14 declare a Pointreference (point1) and a Circlereference (circle1). Lines 16 17 append Stringrepresentations of each object to Stringoutputto show the values used to initialize these objects. Because point1is reference to a Pointobject,
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Leave a Reply