i have noticed that methods get overriden but the variables do not specially when i equate asuper class to a sub class why does this happen.
taking for eg.
class Base
{
int i=23;
void show()
{
System.out.println("from super");
}
}
class Sub extends Base
{
int i = 34;
Sub(){}
void show()
{
System.out.println("from sub");
}
}
class testoverride
{
public static void main(
String[] as)
{
Sub s= new Sub();
Base b = new Base();
b=s;
b.show();
System.out.println(b.i);
}
}
the result is
from sub
23//not 34
why is not the variable of the sub class getting called??
please help me with this
ruchi