396 Object-Oriented Programming: (Web hosting billing) Polymorphism Chapter 10 32 set

396 Object-Oriented Programming: Polymorphism Chapter 10 32 set 33 { 34 x = value; // no validation needed 35 } 36 } 37 38 // property Y 39 public int Y 40 { 41 get 42 { 43 return y; 44 } 45 46 set 47 { 48 y = value; // no validation needed 49 } 50 } 51 52 // return string representation of Point2 object 53 public override string ToString() 54 { 55 return “[” + X + “, ” + Y + “]”; 56 } 57 58 // implement abstract property Name of class Shape 59 public override string Name 60 { 61 get 62 { 63 return “Point2″; 64 } 65 } 66 67 } // end class Point2 Fig. 10.5 Fig. 10.5Fig. 10FiFi.5g. 10.5g. 10.5Point2class inherits from abstractclass Shape. (Part 2 of 2.) Figure 10.6 defines class Circle2, which inherits from class Point2. Class Circle2contains property Radius(lines 24 37) for accessing the circle s radius. Note that we do not declare property Radius as virtual, so classes derived from this class cannot override this property. A circle has zero volume, so we do not override base-class method Volume. Rather, Circle2 inherits this method from class Point2, which inherited the method from Shape. However, a circle does have an area, so Circle2overrides Shapemethod Area(lines 52 55). Property Name(lines 65 71) of class Circle2 overrides property Name of class Point2. If this class did not override property Name, the class would inherit the Point2 version of property Name. In that case, Circle2 s Nameproperty would erroneously return Point2.
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Leave a Reply