what is the benefit of dynamic binding over static one.. If we want to access the methods of sub class then we can make an object of the same with reference variable of sub class type…. what is the benefit if we want to call a method of sub class and using reference variable of super class type?
class Human{
public void walk()
{
System.out.println("Human walks");
}
}
class Boy extends Human{
public void walk(){
System.out.println("Boy walks");
}
public static void main( String args[]) {
//Reference is of parent class
Human myobj = new Boy();
myobj.walk();
}
}
O/p :Boy walks
In the above example why do we need to use "Human myobj = new Boy();" instead we can use "Boy myobj = new Boy();" My point is what is the use of assigning super class reference to sub class object. I am really confused about this. Please help me..