Please check this code:
==========================================
class Base{
int i = 5;
void methodA(){
System.out.println("methodA from Base");
}
}
class Sub extends Base{
int i = 10;
void methodA(){
System.out.println("methodA from Sub");
}
public static void main(
String a[]){
Base oBase = new Sub();
System.out.println(oBase.i); //still its refering to Base i and printing 5
oBase.methodA(); //calling sub class method.
}
}
===========================================
Here variable is pointing to Base class and method is pointing to Sub class. Why??? Your help will be appreciated.
Thanks.