Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default 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()

  2. #2
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: Inheritance hierarchy question

    bump, anybody?

  3. #3
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default 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
    Java 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 B
    Java Code:
    public class ClassB extends ClassA {
    	
    	public void doSomething()
    	{
    		System.out.println("ClassB.java"); 
    	}
    
    }
    Class A
    Java Code:
    public class ClassA {
    	
    	public void doSomething()
    	{
    		System.out.println("ClassA.java"); 
    	}
    
    }

    The output is: "ClassB.java"

  4. #4
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Help with inheritance/hierarchy
    By klz215 in forum New To Java
    Replies: 2
    Last Post: 02-23-2012, 09:42 PM
  2. inheritance question
    By Jaevko in forum New To Java
    Replies: 7
    Last Post: 08-31-2011, 08:30 AM
  3. A question about inheritance / polymorphism
    By gabriels in forum New To Java
    Replies: 2
    Last Post: 02-26-2011, 12:53 PM
  4. Question about inheritance
    By hei1233212000 in forum New To Java
    Replies: 3
    Last Post: 11-12-2010, 12:38 PM
  5. a question about inheritance
    By litojs in forum New To Java
    Replies: 8
    Last Post: 11-10-2008, 11:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •