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

Slightly more subtle inheritance issue.

 
Neil Mac
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If I have classes Sub2 which inherits from Sub1 which in turn inherits from Super1 and each class defines the instance method someMethod() (i.e. Sub1 and Sub2 override the method)...
How can I access the top level class definition of someMethod() from Sub2 ?
I can't use super.someMethod() as that will invoke the method defined in Sub1 and I can't cast the 'this' reference as that only casts the reference type and has no bearing on which method is executed.
I'm going to stick my neck out here and say that it can't be done...
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct - you can't do that.
 
Sainudheen Mydeen
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
new Super1().someMethod(); will work.
---------------
Sainudheen
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spider Man:
Welcome to JavaRanch!
We don't have many rules here at JavaRanch, but we do have one. Please change your display name to comply with The JavaRanch Naming Policy. (We are looking for names that are not obviously fictitious...)
Thanks Pardner! Hope to see you around the Ranch!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic