0

I know in Java, especially when you do field hiding, you are able to access grandparent's state variables:

((Grandparent) this).hiddenField

Why is the same rationale not the case for method calls? you can call super.method(), why not other ancestor's as well?

user1329572
  • 6,176
  • 5
  • 29
  • 39
Bober02
  • 15,034
  • 31
  • 92
  • 178

2 Answers2

1

Because methods are virtual, and fields are not. The goal was to call the same method regardless of the type of reference:

(Grandparent) this).method() always equals this.method().

Alexei Kaigorodov
  • 13,189
  • 1
  • 21
  • 38
1

There is no analog of field hiding for instance methods. Instance methods, unlike instance fields or static methods, are subject to dynamic dispatch and that's a whole different story. In a sense, an overridden method is just not "there" anymore, and the only exception is within the overriding method body, and there only the method being directly overridden.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436