why we can't override the variables in java , It hides variable
class A {
int a = 4;
public void test(){
System.out.println("Test method of A" );
}
}
class B extends A {
int a = 5;
public void test(){
System.out.println("Test method of B" );
}
public static void main(String s[]){
A a= new B();
System.out.println("Value of a : " a.a );
System.out.println("Method result " a.test() );
}
}
Output ::
Value of a : 4
Mthod result :Test method of B
As the B's class test method get called but variable was accessed from super class reference