Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing methods in super super class

 
Dan Culache
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can one access method m() of class A using an instance of class C?
 
Basanti Mathad
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I guess its not possible to access the method...
basanti
 
Ho Gong
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dan Culache:
How can one access method m() of class A using an instance of class C?
 
Mellihoney Michael
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mellihoney Michael:
<hr></blockquote>[/QB]
 
Dan Culache
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael, your solution contradicts the very idea of polymorphism. See Kathy's answer.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael, your example will always run method m in class C.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic