Results 1 to 4 of 4
Thread: Inheritance hierarchy question
- 04-05-2012, 11:33 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 8
- Rep Power
- 0
Inheritance hierarchy question
Okay, let's say there are 3 classes.
public class theA Methods
int move()
public class theB extends theA
double move()
public class theC extends theB
int doSomething()
if declarations is
theC newC = new theC();
newC.move() // which move() will it call to? theA or theB's move()
- 04-06-2012, 12:01 AM #2
Member
- Join Date
- Jan 2012
- Posts
- 8
- Rep Power
- 0
Re: Inheritance hierarchy question
bump, anybody?
- 04-06-2012, 12:21 AM #3
Senior Member
- Join Date
- Feb 2012
- Posts
- 219
- Rep Power
- 2
Re: Inheritance hierarchy question
I threw something together quick as a test. If everything worked out right, I think you may have your answer
Class C
Class BJava Code:public class ClassC extends ClassB{ public ClassC() { // TODO Auto-generated constructor stub } /** * @param args */ public static void main(String[] args) { ClassC classc = new ClassC(); classc.doSomething(); } }
Class AJava Code:public class ClassB extends ClassA { public void doSomething() { System.out.println("ClassB.java"); } }
Java Code:public class ClassA { public void doSomething() { System.out.println("ClassA.java"); } }
The output is: "ClassB.java"
- 04-06-2012, 12:55 AM #4
Member
- Join Date
- Jan 2012
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
Help with inheritance/hierarchy
By klz215 in forum New To JavaReplies: 2Last Post: 02-23-2012, 08:42 PM -
inheritance question
By Jaevko in forum New To JavaReplies: 7Last Post: 08-31-2011, 07:30 AM -
A question about inheritance / polymorphism
By gabriels in forum New To JavaReplies: 2Last Post: 02-26-2011, 11:53 AM -
Question about inheritance
By hei1233212000 in forum New To JavaReplies: 3Last Post: 11-12-2010, 11:38 AM -
a question about inheritance
By litojs in forum New To JavaReplies: 8Last Post: 11-10-2008, 10:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks