aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Accessing methods in super super class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Accessing methods in super super class" Watch "Accessing methods in super super class" New topic
Author

Accessing methods in super super class

Dan Culache
Ranch Hand

Joined: Jan 24, 2003
Posts: 70
How can one access method m() of class A using an instance of class C?
Basanti Mathad
Ranch Hand

Joined: Aug 27, 2002
Posts: 60
Hi,
I guess its not possible to access the method...
basanti
Ho Gong
Greenhorn

Joined: Jan 10, 2003
Posts: 8
You can call super.m1() in C's m1() but it calls B's m1(). If you call, cObj.m1(), C's m1 will call.
thank you.
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
There's no super.super.super syntax or greatgrandparent.method() syntax
The only way a something-above-super version will run is if there is a "super chain" where the super version ALSO invokes its super version and so on...
So no, you can't control it directly. A super.something() will always take you to the version you inherited.
In a decent design this shouldn't pose a problem, but since I know you're studying for the exam -- which has so LITTLE to do with the *real* world, it's a really good question to ask
cheers,
Kathy
p.s. thanks for your good errata Dan! It should be posted tonight or tomorrow early. We'll let everybody know where to find it.
Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
Originally posted by Dan Culache:
How can one access method m() of class A using an instance of class C?


a beginner in java
Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
Originally posted by Mellihoney Michael:
<hr></blockquote>[/QB]
Dan Culache
Ranch Hand

Joined: Jan 24, 2003
Posts: 70
Michael, your solution contradicts the very idea of polymorphism. See Kathy's answer.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Michael, your example will always run method m in class C.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing methods in super super class
 
Similar Threads
Q on overriding
About polymorphism
I dont understand why does it show error
Hiding of instance variables. Hard question?
this and super