954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

a question about inherite classes

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

zouyu1983
Newbie Poster
5 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

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

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

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 [inl;inecode]java.applet.Applet[/inlinecode] 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.

DavidRyan
Posting Whiz in Training
229 posts since Jul 2006
Reputation Points: 22
Solved Threads: 11
 

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

farook ahammad
Newbie Poster
5 posts since Sep 2006
Reputation Points: 13
Solved Threads: 0
 

derive1.f();

farook ahammad
Newbie Poster
5 posts since Sep 2006
Reputation Points: 13
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You