• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing Super.Super from derived class

 
Arvind Varma
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why cannot we call super.super.someMethod()
in class A that extends B that in turn extends C. all of them implement
someMethod().
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it would break encapsulation: A shouldn't need to know that B extends C, as this is an implementation detail of B. It would make your design much more fragile if A would know.
Why do you want to? We probably could find a more appropriate solution...
 
Arvind Varma
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats true...I understand its more of a design decision than an implementation Issue. So basically in order to support encapsulation java doesn't allow to access C from A(i tried doing that and got an error thrown). Correct me if i'm wrong
It is more out of curiosity that i wanted to know why is it like that.
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic