Saturday, May 2, 2015

Difference between P p = new C() and C c = new C()

C c = new C()
  1. If we know exact runtime type of object then we should use this approach
  2. by using child reference we can call both parent and child methods
P p = new C()
  1. If we dont know exact runtime type of object then we should use this approach(Polymorphism)
  2. by using parent reference we can call only methods available in parent class and child class methods we cant call.

    No comments:

    Post a Comment