I was trying to understand static variables in Java and what I see is following behaviour
public class TestParent {
protected static String name = "parent";
}
public class TestChild extends TestParent{
public TestChild(){
super.name="child";
}
}
Now if
TestParent tp = new TestParent();
output:
parent
else if,
TestParent tp = new TestChild();
output: child
Can someone explain to me what exactly is happening? I know this question sounds very simple but I am not able to understand the reason.
Thanks.