Can I call a parent class overridden method with the child class object in java?
I tried below example
class First1 { void show() { String msg="You are in first class"; System.out.println(msg); } } class second extends First1 { void show() { String msg="You are in second class"; System.out.println(msg); } } } class CallingMethod extends second { void show() { String msg="You are in the third class"; System.out.println(msg); } public static void main(String[] args) { CallingMethod cm=new CallingMethod(); cm.show(); }
}
Now tell me if it is possible to print "I am in second class." by using the object of CallingMethod class that is cm here in example and without using super keyword anywhere.