In this case, you should remember that in java you cannot overestimate static methods. What happened is to hide the material.
according to the code you supplied, if you follow these steps, the answer will be null
Parent.ACONSTANT == null ; ==> true Parent p = new Parent(); p.ACONSTANT == null ; ==> true Parent c = new Child(); c.ACONSTANT == null ; ==> true
while you use Parent as a reference type, ACONSTANT will be null.
will allow you to do something like this.
Child c = new Child(); c.ACONSTANT = "Hi"; Parent p = c; System.out.println(p.ACONSTANT);
The output will be zero.
source share