I have two classes :TestClass2 and TestClass3 . TestClass3 extends TestClass2.
public class TestClass2 {
static int i=10;
static int k=TestClass3.j+100;
}
public class TestClass3 extends TestClass2{
static int j=20;
}
Now when in another class when I print :
public static void main(String[] args) {
System.out.println(TestClass3.j);
System.out.println(TestClass2.k);
}
I get the result as 20 and 100
But when I just Print TestClass2.K (something like below)I get the result as 120.
public static void main(String[] args) {
System.out.println(TestClass2.k);
}
Can someone please explain why this may be happening?