class SubClass extends SuperClass
1) SubClass s1 = new SubClass();
2) SuperClass s2 = new SubClass();
Explanation of first one:-
s1 is the refernce of subclass and holds a object of sub class, so it will call the method of subclass as well as super class because we extends the superclass method with subclass method so superclass method will automatically available to subclass.we can call both super class as well as sub class method with the help of s1.
Explanation of second one:-
s2 is the refernce of Superclass and holds a object of sub class,so here two case we have to consider
i) Method overloading:-method overloading is handle at compile time so it will always call the method of superclass
ii)Method overriding:-method overriding is handle at runtime so it always call the method of subclass. the concept came from the polymorphism.
SubClass s1 = new SubClass();
SubClass s2 = new SubClass();
both s1 and s2 are reference of subclass and holding the object of subclass so in both case it will call the subclass object.
SuperClassons2.