This week's giveaway is in the Cloud/Virtualization forum. We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line! See this thread for details.
Within a class, a field that has the same name as a field in the superclass hides the superclass's field, even if their types are different. - Java Tutorials
Overridden Instance Method
An instance method in a subclass with the same signature (name, plus the number and the type of its parameters) and return type as an instance method in the superclass overrides the superclass's method. - Java Tutorials
You need to be more specific. You added those print statements inside your getter methods which produce extra output. If you are confused about variable hiding and method overriding there is a quite good explanation on DZone
You are correct about variable hiding, but you are wrong about execution order. When you call the getH() method, you get the overriding version in both cases because the runtime type of the object is Beta. What conusing names for the classes; if you had called them Superclass and Subclass, he problem would have been easier to understand. That means the class name is printed before the print statements in line 21 ans 23 can run. In both cases, since you are using the subclass' method, the sbcass' field is used. In line 21, however, the field is called on the declared type of the variable, so you get 4 printed, only not where you think it would be printed. In line 23, yuo are using the declared type of Beta, so the variable 44 is found.
That tutorial correctly explains variable hiding, but it has a very confusing spelling error in, and it uses the misleading parent/child terminology which so many people seem to like.