Results 1 to 3 of 3
  1. #1
    McChill is offline Member
    Join Date
    Feb 2009
    Posts
    47
    Rep Power
    0

    Default Interface Inheritance

    Whenever I make the class Q, i get a compile error saying "The type Q must implement the inherited abstract method P12.display()"

    I get that I have to put the implementation for display() somewhere in Q (or close to in Q..?), but I'm confused by how to do it. I tried putting
    Java Code:
    void display()
    {
    System.out.println("DISPLAY");
    }
    but it didn't work. I tried just putting void display() {} in Q but that did not work.

    This is my code so far...

    Java Code:
    interface P {
    	
    	String P = "P";
    	void display();
    	
    	
    }
    Java Code:
    interface P1 extends P {
    
    	String P1 = "P1";
    	
    	
    }
    Java Code:
    interface P2 extends P{
    	
    	void display();
    	String P2 = "P2";
    
    }
    Java Code:
    interface P12 extends P1, P2{
    
    	void display();
    	String P12 = "P12";
    	
    	
    }
    Java Code:
    public class Q implements P12{
    	
    	
    	
    
    }
    Any help would be appreciated.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Does your method need to have the "public" keyword at its declaration in Q?

  3. #3
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    Java Code:
    [B]public[/B] void display()
    {
    System.out.println("DISPLAY");
    }
    edit:
    methods in interfaces are public, when you declared void display(), that's default package which is weaker.
    Last edited by angryboy; 03-04-2009 at 04:13 AM.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. Inheritance
    By mew in forum New To Java
    Replies: 1
    Last Post: 12-07-2007, 07:08 PM
  2. Inheritance in GUI
    By Marty in forum SWT / JFace
    Replies: 2
    Last Post: 05-11-2007, 01:54 AM

Posting Permissions

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