374 Object-Oriented Programming: Inheritance Chapter 9 Class Circle5(Fig. (Web hosting faq)

374 Object-Oriented Programming: Inheritance Chapter 9 Class Circle5(Fig. 9.18) contains the features in Fig. 9.13, and we modified the two constructors (lines 12 16 and 19 24) to output a line of text when they are called. We also added a destructor (lines 27 30) that also outputs a line of text when it is called. Each output statement (lines 15, 23 and 29) adds reference this to the output string. This implicitly invokes the Circle5 s ToString method to obtain the string representation of Circle5 s coordinates and radius. Class ConstructorAndFinalizer (Fig. 9.19) demonstrates the order in which constructors and finalizers are called for objects of classes that are part of an inheritance class hierarchy. Method Main (lines 11 28) begins by instantiating an object of class Circle5, then assigns it to reference circle1 (line 16). This invokes the Circle5 constructor, which invokes the Point4constructor immediately. Then, the Point4constructor invokes the Objectconstructor. When the Objectconstructor (which does not print anything) returns control to the Point4constructor, the Point4constructor initializes the x-y coordinates, then outputs a string indicating that the Point4 constructor was called. The output statement also calls method ToStringimplicitly (using reference this) to obtain the stringrepresentation of the object being constructed. Then, control returns to the Circle5 constructor, which initializes the radius and outputs the Circle5 s x-y coordinates and radius by calling method ToStringimplicitly. 1 // Fig. 9.18: Circle5.cs 2 // Circle5 class that inherits from class Point4. 3 4 using System; 5 6 // Circle5 class definition inherits from Point4 7 public class Circle5 : Point4 8 { 9 private double radius; 10 11 // default constructor 12 public Circle5() 13 { 14 // implicit call to Point3 constructor occurs here 15 Console.WriteLine( “Circle5 constructor: {0}”, this ); 16 } 17 18 // constructor 19 public Circle5( int xValue, int yValue, double radiusValue ) 20 : base( xValue, yValue ) 21 { 22 Radius = radiusValue; 23 Console.WriteLine( “Circle5 constructor: {0}”, this ); 24 } 25 26 // destructor overrides version in class Point4 27 ~Circle5() 28 { 29 Console.WriteLine( “Circle5 destructor: {0}”, this ); 30 } Fig. 9.18 Fig. 9.18Fig. 9.FiFi18g. 9.18g. 9.18Circle5class inherits from class Point3and overrides a finalizer method. (Part 1 of 2.)
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Leave a Reply