class Testing{
public static void main(String[] args) {
Animal d = new Dog();
/*This is totally legal, calling
the method run is no problem
because it is defined inside
the Animal class: */
d.run();
/*Compliler Error! Calling
the method bark results
in an error because it is
not defined in the Animal
class: */
d.bark();
}
}
My Question is:
- Why subclass method cannot be called when it has super class refernce? How it internally stored?
- Usually super class refernce is used to point the sub class objects, If we cant call subclass specific methods, then where its prefered to have super class refernce to sub class object, i means whats the scenario?