InterviewSolution
Saved Bookmarks
| 1. |
MultiLevel Inheritance in C# |
|
Answer» The functionality of a class can be inherited by another class USING inheritance. The original class is known as the base class and the class which inherits the functionality of the base class is known as the derived class. Multilevel inheritance involves a class that inherits from a derived class. This derived class may have inherited from the base class or from another derived class and so on. A PROGRAM that demonstrates multilevel inheritance in C# is given as follows: using System; namespace Demo { class ClassX { public INT x; public ClassX() { x = 23; } } class ClassY: ClassX { public int y; public ClassY() { y = 91; } } class ClassZ: ClassY { public int z; public ClassZ() { z = 67; } } class Test { static void Main(string[] args) { ClassZ OBJ = new ClassZ(); Console.WriteLine("x = {0}", obj.x); Console.WriteLine("y = {0}", obj.y); Console.WriteLine("z = {0}", obj.z); } } }The output of the above program is as follows: x = 23 y = 91 z = 67 |
|