public static void Demo() { Console.WriteLine($"Simple Inheritance"); Console.WriteLine(); BaseClass parent = new BaseClass(); parent.Method1(); parent.Method2(); ChildA childA = new ChildA(); childA.Method1(); childA.Method2(); childA.Method3(); ChildB childB = new ChildB(); childB.Method1(); //method hiding childB.Method2(); //method override BaseClass parent2 = (BaseClass)childB; parent2.Method1(); // calling BaseClass method parent2.Method2(); // derived method will run since it overrides BaseClass Console.WriteLine($"------------------------"); Console.WriteLine(); }
public static void Demo() { Helpers.DisplaySectionTitle("Simple Inheritance"); BaseClass parent = new BaseClass(); parent.Method1(); parent.Method2(); ChildA childA = new ChildA(); childA.Method1(); childA.Method2(); childA.Method3(); ChildB childB = new ChildB(); childB.Method1(); //method hiding childB.Method2(); //method override BaseClass parent2 = (BaseClass)childB; parent2.Method1(); // calling BaseClass method parent2.Method2(); // derived method will run since it overrides BaseClass Helpers.DisplaySectionEnd(); }
public static void Demo() { Helpers.DisplaySectionTitle("Sealed"); BaseClass parent = new BaseClass(); parent.Method1(); parent.Method2(); ChildA childA = new ChildA(); childA.Method1(); childA.Method2(); ChildB childB = new ChildB(); childB.Method1(); childB.Method2(); // ChildA.Method2() will be shown since it cannot be further overriden Helpers.DisplaySectionEnd(); }
public static void Demo() { Console.WriteLine($"Sealed"); Console.WriteLine(); BaseClass parent = new BaseClass(); parent.Method1(); parent.Method2(); ChildA childA = new ChildA(); childA.Method1(); childA.Method2(); ChildB childB = new ChildB(); childB.Method1(); childB.Method2(); // ChildA.Method2() will be shown since it cannot be further overriden Console.WriteLine($"------------------------"); Console.WriteLine(); }