*
The moose likes Beginning Java and the fly likes super.super Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "super.super" Watch "super.super" New topic
Author

super.super

alec stewart stewart
Ranch Hand

Joined: Dec 23, 2003
Posts: 71
hi all

suppose we have a class a which extends b and b in turn extends c

all three classes have a method tell();

now how do i call the method tell of c from a

can i do like this super.super

and also what will be the super class of a will it be b or c
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
because a extends b, b is the superclass

You cannot access the methods in c if b overrides them.
Abdulla Mamuwala
Ranch Hand

Joined: Jan 09, 2004
Posts: 225

because a extends b, b is the superclass
You cannot access the methods in c if b overrides them.


Steven please can you explain your statement in reference to the following code below,


In the code above, engine() is a method present in LuxaryCar, Buick and BuickLeSabre but I am still accessing method engine() of LuxaryCar. I think that was the question that Alec had.

suppose we have a class a which extends b and b in turn extends c
all three classes have a method tell();
now how do i call the method tell of c from a


Also Steven please can you explain this particular statement with reference to what doubt Alec had,

You cannot access the methods in c if b overrides them.


I think you forgot to mention Where you cannot access the methods and Why ?, I think after that explaination your answer would be complete.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

I think Alec was awfully clear:


now how do i call the method tell of c from a


He wants to call the version of "tell" inherited from "c" directly from "a". Steven's answer is concise and correct -- it can't be done. No need for any examples: both Alec and Steven understand one another.


[Jess in Action][AskingGoodQuestions]
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
It's a security issue. A may not know all the reasons B overrode C's method. To allow A to bypass B and directly access the method in C could cause problems.

Suppose C was a generic elevator control object. The original designers used Imperial units to control the maximum velocity of the elevator. B comes along and overrides C's move method so it now takes velocities in metric units. Finally A comes along and wants to change the acceleration profile so it moves smoothly but doesn't realize B.move was actually a wrapper function that changed the units. A bypasses B completely and calls super.super.move() with Metric velocity units.

Elevator crashes. People die.

Java prevents direct access to "grandparent" methods to prevent this from happening. Also note this is true for methods AND constructors for the same reason.

Cheers,


Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: super.super
 
Similar Threads
Anyhting like super.super?
Accessing Super.Super from derived class