398 Object-Oriented Programming: Polymorphism Chapter 10 54 return (Apache web server for windows)

398 Object-Oriented Programming: Polymorphism Chapter 10 54 return Math.PI * Math.Pow( Radius, 2 ); 55 } 56 57 // return string representation of Circle2 object 58 public override string ToString() 59 { 60 return “Center = ” + base.ToString() + 61 “; Radius = ” + Radius; 62 } 63 64 // override property Name from class Point2 65 public override string Name 66 { 67 get 68 { 69 return “Circle2″; 70 } 71 } 72 73 } // end class Circle2 Fig. 10.6 Fig. 10.6Fig. 10FiFi.6g. 10.6g. 10.6Circle2class that inherits from class Point2. (Part 2 of 2.) Figure 10.7 defines class Cylinder2, which inherits from class Circle2. Class Cylinder2contains property Height(lines 24 37) for accessing the cylinder s height. Note that we do not declare property Heightas virtual, so classes derived from class Cylinder2 cannot override this property. A cylinder has different area and volume calculations from those of a circle, so this class overrides method Area(lines 40 43) to calculate the cylinder s surface area (i.e., 2pr2 + 2prh) and overrides method Volume (lines 46 49). Property Name(lines 58 64) overrides property Name of class Circle2. If this class did not override property Name, the class would inherit property Name of class Circle2, and this property would erroneously return Circle2. 1 // Fig. 10.7: Cylinder2.cs 2 // Cylinder2 inherits from class Circle2 and overrides key members. 3 using System; 4 5 // Cylinder2 inherits from class Circle2 6 public class Cylinder2 : Circle2 7 { 8 private double height; // Cylinder2 height 9 10 // default constructor 11 public Cylinder2() 12 { 13 // implicit call to Circle2 constructor occurs here 14 } 15 Fig. 10.7 Fig. 10.7Fig. 10FiFi.7g. 10.7g. 10.7Cylinder2class inherits from class Circle2. (Part 1 of 2.)
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Leave a Reply