• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Peter Rooke
Bartenders:

Call a method in super's super class??

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???

 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sivakumar k r:
Is there a way to call A's display from C's display directly



No.
 
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 23965
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic