// This calls the Draw() method of the ThreeDCircle.
ThreeDCircle o = new ThreeDCircle();
o.Draw();
// This calls the Draw() method of the parent!
((Circle)o).Draw();
Console.ReadLine();
}
■
Source Code
The Shapes project can be found under the Chapter 6 subdirectory.
Understanding Base Class/Derived Class
Casting Rules
Now that you can build a family of related class types, you need to learn the laws of class type cast-
ing operations. To do so, let’s return to the Employees hierarchy created earlier in this chapter.
Under the .NET platform, the ultimate base class in the system is System.Object. Therefore, every-
thing “is-a” Object and can be treated as such. Given this fact, it is legal to store an instance of any
type within an object variable:
Do'stlaringiz bilan baham: |