.Net inheritance and method overloading

前端 未结 5 968
清酒与你
清酒与你 2021-02-20 11:15

Here is a code sample:

class Program
{
    static void Main(string[] args)
    {
        var obj = new DerivedClass();
        obj.SomeMethod(5);
    }
}

class          


        
5条回答
  •  说谎
    说谎 (楼主)
    2021-02-20 11:52

    What I understand is that, since overriding/hiding is not applied, method of derived class is called as it is instantiated in main().

    In Method Overriding: Base class reference variable pointing to child class object will invoke the overridden method in child class. “Override” keyword is used in derived class method signature.

    In Method Hiding: Base class reference variable pointing to child class object will invoke the hidden method in base class. “New” keyword is used in derived class method signature.

提交回复
热议问题