0

Hi, guys. i'm a newbie in java world,now i confront a question about the inherite classes.

class Base {
    void f() {....}
}
 
class Derive1 extends Base {
    void f() {....}
}
 
class Derive2 extends Derive1 {
    void f() {....}
}

i know that if i want to call the f() belongs to Derive1 in the f() belongs to Derive2, i can just write super.f().
Then that's the question, i want to call the f() belongs to Base in the f() function of Derive2, now , what should i do?

TIA
:eek:
smallrain

4
Contributors
4
Replies
5
Views
11 Years
Discussion Span
Last Post by farook ahammad
0

You can't.
A class knows nothing about classes deriving from it and even less about other classes deriving from its own baseclass.

0

I think you read his post wrong jwenting.
I read it that he has three classes, those being Base, Derive1 and Derive2. Derive2 is a subclass of Derive1, and Derive1 is a subclass of Base.
super.f(), when used inside Derive2 calls Derive1.f()
If you are wanting to call the f() defined in Base, you would use the fully qualified name of the class (eg java.applet.Applet in stead of Applet) in this case it would depend on what packages your Base class is a member of. If the Base class is not a member of any packages, then Base.f() should work.

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.