• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

super.super

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

suppose we have a class a which extends b and b in turn extends c

all three classes have a method tell();

now how do i call the method tell of c from a

can i do like this super.super

and also what will be the super class of a will it be b or c
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because a extends b, b is the superclass

You cannot access the methods in c if b overrides them.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


because a extends b, b is the superclass
You cannot access the methods in c if b overrides them.



Steven please can you explain your statement in reference to the following code below,


In the code above, engine() is a method present in LuxaryCar, Buick and BuickLeSabre but I am still accessing method engine() of LuxaryCar. I think that was the question that Alec had.


suppose we have a class a which extends b and b in turn extends c
all three classes have a method tell();
now how do i call the method tell of c from a



Also Steven please can you explain this particular statement with reference to what doubt Alec had,


You cannot access the methods in c if b overrides them.



I think you forgot to mention Where you cannot access the methods and Why ?, I think after that explaination your answer would be complete.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Alec was awfully clear:


now how do i call the method tell of c from a



He wants to call the version of "tell" inherited from "c" directly from "a". Steven's answer is concise and correct -- it can't be done. No need for any examples: both Alec and Steven understand one another.
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a security issue. A may not know all the reasons B overrode C's method. To allow A to bypass B and directly access the method in C could cause problems.

Suppose C was a generic elevator control object. The original designers used Imperial units to control the maximum velocity of the elevator. B comes along and overrides C's move method so it now takes velocities in metric units. Finally A comes along and wants to change the acceleration profile so it moves smoothly but doesn't realize B.move was actually a wrapper function that changed the units. A bypasses B completely and calls super.super.move() with Metric velocity units.

Elevator crashes. People die.

Java prevents direct access to "grandparent" methods to prevent this from happening. Also note this is true for methods AND constructors for the same reason.

Cheers,
reply
    Bookmark Topic Watch Topic
  • New Topic