Purpose of assigning objects of subclass to a superclass reference?
问题 I have always this question burning in me. Why do people assign objects of subclass to a superclass reference as below: What exactly are the benefits and reasons that makes people do so? public static void main(String[] args) { A obj1 = new C(); //Why do this ? C obj2 = new C(); //When we can simply do this ??? } class A {} class B extends A {} class C extends B {} I understands all the logic where a Class Dog is an Animal but Animals are not essentially Dogs. I've also bumped into this link: