Results 1 to 3 of 3
  1. #1
    monocole is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Extends a class that implements an interface

    I have a class

    public class Element implements Comparator{

    and another class
    public class Block extends Element {

    Shouldn't the class Block implements Comparator!?!? I have a lot of extension of Element there is a easy way to implement this in each child of Block?

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Extends a class that implements an interface

    The best way to check is by writing a simple tester program that uses the comparator of the sub class. It will either work, or cause an error.

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: Extends a class that implements an interface

    When a class extends another class it inherits all public methods and fields, therefore it should work without Block needing to implement the Compare interface as the public method compare(Obj, Obj) will be inherited from your Element class.

Similar Threads

  1. Replies: 4
    Last Post: 01-17-2012, 12:39 AM
  2. Advanced extends and implements
    By V1C3M4N in forum Advanced Java
    Replies: 15
    Last Post: 11-17-2010, 01:28 PM
  3. Interface and implements
    By Bored2 in forum New To Java
    Replies: 27
    Last Post: 11-10-2010, 01:08 PM
  4. Replies: 3
    Last Post: 03-19-2009, 05:00 PM
  5. Implements MyClass extends JFrame
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 03:43 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
  •