What is the difference between base reference type vs derived reference type

后端 未结 6 807
清酒与你
清酒与你 2021-01-07 13:20
class Dog
{
}
class BullDog : Dog
{
}
class Program
{
    static void Main()
    {
        Dog dog2 = new BullDog();
        BullDog dog3 = new BullDog();
    }
}
         


        
6条回答
  •  春和景丽
    2021-01-07 14:05

    You don't need Dog dog2 = new BullDog(), you will be able to pass your BullDog to any method expecting a Dog.

    Take a look at http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming

提交回复
热议问题