File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Accessing Super.Super from derived class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Accessing Super.Super from derived class" Watch "Accessing Super.Super from derived class" New topic
Author

Accessing Super.Super from derived class

Arvind Varma
Ranch Hand

Joined: Dec 24, 2002
Posts: 48
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

Joined: Jul 11, 2001
Posts: 14112
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...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Arvind Varma
Ranch Hand

Joined: Dec 24, 2002
Posts: 48
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing Super.Super from derived class