Possible Duplicate:
Hiding instance variables of a class
I have below class
AbstractTest
public abstract class AbstractTest {
protected int testVar = 10;
}
Test
public class Test extends AbstractTest {
int testVar = 5;
public static void main(String[] args) {
AbstractTest test = new Test();
System.out.println(test.testVar);//Prints 10
Test secondTest = new Test();
System.out.println(secondTest.testVar);//Prints 5
}
}
Why above program prints 10 for first case and 5 for second case though it is object of same class i.e. Test()?
Update:
I am now confused about how memory is allocated to Object and its variables. As instance variable is getting changed based on Class which is behaviour of Static?
Update:1
Every object will have two variables so question of same memory allocation does not comes in to picture. Thanks.
This is defined in JLS 15.11.1