This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Call a method in super's super class?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Call a method in super Watch "Call a method in super New topic
Author

Call a method in super's super class??

sivakumar k r
Greenhorn

Joined: Jan 17, 2007
Posts: 4
Hi Folks,

1) Class A is the Super class and B extends from A
2) Class C extends B
3) The method display has been over-ridden in all the classes.
4) From the method in class C, I wish to call that of B & A.
5) I am able to call that of B using super.

Question: Is there a way to call A's display from C's display directly???



Shiv.. as I know him
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by sivakumar k r:
Is there a way to call A's display from C's display directly


No.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
Hi,
class C extends B {
public void display() {
new A().display(); // call like this
System.out.println("Display of Class C called");
super.display(); // calls B's Display
}}
}
}


bye for now
sat
sivakumar k r
Greenhorn

Joined: Jan 17, 2007
Posts: 4
Class C = A + B + delta C.
I wanted to call C's --> A's display.

I didn't want to call display by simply create an object of A and calling the method from that newly created object within C.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

Originally posted by sivakumar k r:
I didn't want to call display by simply create an object of A and calling the method from that newly created object within C.


Unfortunately, the answer is still "no".

Think of it like this. You are the designer of class C, which inherits from B. Your class overrides B, and implements new functionality. But one of the reasons why you override certain methods is that some of the methods of B, are no longer valid, for your C class -- you need those objects overriden, or your class will not function correctly.

Now... do you really want some other developer to create a D class which subclasses your C class, and bypasses the method calls that you overriden?

Henry
[ February 08, 2007: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I wouldn't say that it's "unfortunate".

The whole desire to call a "super's super method" is an indication that you should rethink your design. There probably is an abstraction missing or something that would obliterate that need.


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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Call a method in super's super class??