Always remember, instance variable can not be overridden. Try below example.
public class A{
public int i = 1;
}
public class B{
public int i=2;
}
public class C{
public static void main(String[] arg){
A a = new B();
System.out.println(a.i);//The output will be 1 and not 2
}
}
No comments:
Post a Comment