| 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.<br /> <br />#:^P
|
 |
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: 16696
|
|
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
|
 |
 |
|
|
subject: Call a method in super's super class??
|
|
|