Wonderful explanation Keith.
The methods listed other than the one with return type D have been added to the class definition. This is a form of bridge method that may be used in generics.
Depending on the reference type, the appropriate bridge method is invoked.
This means that if a reference of type A refers to an object of type D, and invokes the method method1(), then the first method invoked will be the one with return type A. Then the overridden method in D will be called. But it will be called from the bridge method. However, the type of object returned by the method will be A.
I don't know anything about bride method. Can you please explain or give me any link to learn?
You can see this by what is printed out in the second set of print statements.
I can't follow the second set of print statement
I guess the answer hidden behind bridge method!!
You know that if you access a static member of a class using an instance of the class, then the class type will be substituted by the compiler in the method call.
So first.method1().x will refer to the static variable x in the class definition which is the type of first.method1().
So 1 is printed.
This point is clear.