Difference between object creation and assignment of Parent Class and Child Class
C c=new C() | P p=new C() |
If we know exact runtime type of object then we should use these approach | If we do not know exact runtime type of object then we should use these approach(polymorphism) |
By using child reference we can call both parent and child class method | By using parent reference we can call only methods available in parent class and child specific methods we cant call |
We can use child reference to hold only for that particular child class object only | We can use parent reference to hold any child class object |