Difference between object a = new Dog() vs Dog a = new Dog()

前端 未结 6 1504
野性不改
野性不改 2020-12-29 04:03
object a = new Dog();

vs

Dog a = new Dog();

In both cases a.GetType() gives Dog. Both

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 04:37

    This is useful when you want to use polymorphism and you can use the abstract method that has implementation in Dog. Therefore, in this way object is Dog, even so is Object. So you may use this manner when you want to use polymorphism.

提交回复
热议问题