posted 17 years ago
Hi,
I am arulraj, i have one doubt in the following code:
class A
{
int x=10;
}
class B
{
int x=20;
}
A a= new B();
System.out.println("value ofx:"+a.x);
What is the output of x?
I thought it will be 20 ,but jvm gives 10...
with respect to overriding, this is ok.... (the method in class b will be called). but for variable, it provide reverse opertion.........
May i know the reason that why is pointing to X containing in class A instead of B.