Chapter 9 Object-Oriented (Web space) Programming: Inheritance 369 11 //
Chapter 9 Object-Oriented Programming: Inheritance 369 11 // default constructor 12 public Cylinder() 13 { 14 // implicit call to Circle4 constructor occurs here 15 } 16 17 // four-argument constructor 18 public Cylinder( int xValue, int yValue, double radiusValue, 19 double heightValue ) : base( xValue, yValue, radiusValue ) 20 { 21 Height = heightValue; // set Cylinder height 22 } 23 24 // property Height 25 public double Height 26 { 27 get 28 { 29 return height; 30 } 31 32 set 33 { 34 if ( value >= 0 ) // validate height 35 height = value; 36 } 37 38 } // end property Height 39 40 // override Circle4 method Area to calculate Cylinder area 41 public override double Area() 42 { 43 return 2 * base.Area() + base.Circumference() * Height; 44 } 45 46 // calculate Cylinder volume 47 public double Volume() 48 { 49 return base.Area() * Height; 50 } 51 52 // convert Cylinder to string 53 public override string ToString() 54 { 55 return base.ToString() + “; Height = ” + Height; 56 } 57 58 } // end class Cylinder Fig. 9.15 Fig. 9.15Fig. 9.FiFi15g. 9.15g. 9.15Cylinderclass inherits from class Circle4and overrides method Area. (Part 2 of 2.) Figure 9.16 is a CylinderTestapplication that tests the Cylinderclass. Line 14 instantiates an object of class Cylinder. Lines 17 19 use properties X, Y, Radius and
In case you need quality webspace to host and run your web applications, try our personal web hosting services.