class super{
public void method1(){
System.out.println("super");
}
class sub extends super{
public void method1(){
System.out.println("sub");
}
public static void main(
String args[]){
super a = new sub();
a.method1(); //1
((sub)a).method1(); //2
}
output==> sub
sub
1>This means during method overriding method is invoked according to class of current object?
2>If super class doesn't have method1() then line 1 will give compiler error saying method1 is not defined in super.but line 2 will give output sub
class of the object is sub then Why line 1 is giving error?
3>Now if method1 is made static in both the classes then line 1 will give output as "super" and line 2 will give output as "sub".
Now method1 is redefined in sub class.then why it is not giving error as static method cann't be overriden?