Chapter 9 Object-Oriented Programming: Inheritance 361 20 21

Chapter 9 Object-Oriented Programming: Inheritance 361 20 21 // set Circle3’s x-y coordinates and radius to new values 22 circle.X = 2; 23 circle.Y = 2; 24 circle.Radius = 4.25; 25 26 // display Circle3’s string representation 27 output += “nn” + 28 “The new location and radius of circle are ” + 29 “n” + circle + “n”; 30 31 // display Circle3’s Diameter 32 output += “Diameter is ” + 33 String.Format( “{0:F}”, circle.Diameter() ) + “n”; 34 35 // display Circle3’s Circumference 36 output += “Circumference is ” + 37 String.Format( “{0:F}”, circle.Circumference() ) + “n”; 38 39 // display Circle3’s Area 40 output += “Area is ” + 41 String.Format( “{0:F}”, circle.Area() ); 42 43 MessageBox.Show( output, “Demonstrating Class Circle3″ ); 44 45 } // end method Main 46 47 } // end class CircleTest3 Fig. 9.11 Fig. 9.11Fig. 9.FiFi11g. 9.11g. 9.11CircleTest3demonstrates class Circle3functionality. (Part 2 of 2.) In the previous example, we declared the base-class instance variables as protected, so that a derived class could modify their values directly. The use of protectedvariables allows for a slight increase in performance, because we avoid incurring the overhead of a method call to a property s set or getaccessor. However, in most C# applications, in which user interaction comprises a large part of the execution time, the optimization offered through the use of protectedvariables is negligible. Using protected instance variables creates two major problems. First, the derived- class object does not have to use a property to set the value of the base-class s protected data. Therefore, a derived-class object can easily assign an illegal value to the protected
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Leave a Reply