Calling child class method from parent

后端 未结 3 1007
故里飘歌
故里飘歌 2021-02-19 12:20

Is it possible for the a.doStuff() method to print \"B did stuff\" without editing the A class? If so, how would I do that?

class Program
{
    static void Main         


        
3条回答
  •  悲&欢浪女
    2021-02-19 13:02

    Since B is effectively A through inheritance and the method is overloaded.

    A a = new B();
    a.doStuff();
    

提交回复
热议问题