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

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

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.

simply write super.f() for calling base class function from derive2 class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.