- using System;
- class BaseClass {
- public BaseClass() {
- Console.WriteLine("Base Class Constructor Called. ");
- }
- }
- class DerivedClassLevel1: BaseClass {
- public DerivedClassLevel1() {
- Console.WriteLine("Derived Class Level1 Constructor Called. ");
- }
- }
- class DerivedClassLevel2: DerivedClassLevel1 {
- public DerivedClassLevel2() {
- Console.WriteLine("Derived Class Level2 Constructor Called. ");
- }
- }
- class UsingBaseClass {
- static void Main(String[] arg) {
- Console.WriteLine("Base Class Object Creating...");
- BaseClass objBase = new BaseClass();
- Console.WriteLine("\nDerived Class Level1 Object Creating...");
- DerivedClassLevel1 objDL1 = new DerivedClassLevel1();
- Console.WriteLine("\nDerived Class Level2 Class Object Creating...");
- DerivedClassLevel2 objDL2 = new DerivedClassLevel2();
- }
- }
Output
Base Class Object Creating...
Base Class Constructor Called.
Derived Class Level1 Object Creating...
Base Class Constructor Called.
Derived Class Level1 Constructor Called.
Derived Class Level2 Class Object Creating...
Base Class Constructor Called.
Derived Class Level1 Constructor Called.
Derived Class Level2 Constructor Called.