C# Saved Program: quiescent-palace

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


using System;


namespace Generics
{
    class BaseClass  
{  
    public void Method1()  
    {  
        Console.WriteLine("Base - Method1");  
    }  
    
    public void Method2()  
    {  
        Console.WriteLine("Base - Method2");  
    }  
}  

class DerivedClass : BaseClass  
{  
    public new void Method2()  
    {  
        Console.WriteLine("Derived - Method2");  
    }  
    
}  

    class Polymorphism
    {
       static void Main(string[] args)  
    {  
        BaseClass bc = new BaseClass();  
        DerivedClass dc = new DerivedClass();  
        BaseClass bcdc = new DerivedClass();  

        bc.Method1();  
        bc.Method2();  
        dc.Method1();  
        dc.Method2();  
        bcdc.Method1();  
        bcdc.Method2(); 
    }  
    }
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs