Since the Java developers decided to make the methods polymorphic (and therefore redefinable), but not fields.
When you reference a field from an object, the compiler decides which field to use based on the type of variable declared, which in this case is Test .
When you reference methods, the JVM at run time chooses which method to call based on the actual concrete type of the object, which in this case is TestChild .
OO is all about encapsulating a state, so you almost never have to open fields outside.
source share