Web site counters - Chapter 9 Object-Oriented Programming: Inheritance 355 45 46

Chapter 9 Object-Oriented Programming: Inheritance 355 45 46 } // end class CircleTest Fig. 9.7 Fig. 9.7Fig. 9.FiFi7g. 9.7g. 9.7CircleTestdemonstrates class Circlefunctionality. (Part 2 of 2.) In the next examples we answer that question, we use a more elegant class construction approach emphasizing the benefits of inheritance. Now, we create and test a class Circle2 (Fig. 9.8) that inherits variables x and y and properties X and Y from class Point (Fig. 9.4). This class Circle2 is a Point (because inheritance absorbs the capabilities of class Point), but also contains radius (line 9). The colon (:) symbol in the class declaration (line 7) indicates inheritance. As a derived class, Circle2 inherits all the members of class Point, except for the constructors. Thus, the public services to Circle2 include the two Circle2constructors (lines 12 24); the public methods inherited from class Point; property Radius(lines 27 40); and the Circle2methods Diameter, Circumference, Areaand ToString(lines 43 65). We declare method Area as virtual, so that derived classes (such as class Cylinder, as we will see in Section 9.5) can override this method to provide a more appropriate implementation. 1 // Fig. 9.8: Circle2.cs 2 // Circle2 class that inherits from class Point. 3 4 using System; 5 6 // Circle2 class definition inherits from Point 7 class Circle2 : Point 8 { 9 private double radius; // Circle2’s radius 10 11 // default constructor 12 public Circle2() 13 { 14 // implicit call to Point constructor occurs here 15 } 16 Fig. 9.8 Fig. 9.8Fig. 9.FiFi8g. 9.8g. 9.8Circle2class that inherits from class Point. (Part 1 of 3.)
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

Leave a Reply