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

interfaces and extending

I started over with reading my certification book, and I'm now on page 113. It says that an interface can extend one or more other interfaces.....I thought you could only extend one thing, or do they mean the interfaces that the extended interface extended?

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

Classes can extend only 1 other class (as well as implementing any number of interfaces).
Interfaces can extend any number of other interfaces (but can't implement anything obviously).

So you can have something like

public interface MyInterface extends List, Serializable, Comparable {
//... method declarations
}
jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Is there a reason they chose to let it extend more than one, instead of letting it implement and not extend?

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

an interface can't implement anything. If it could you'd have an abstract class.
Something like

public interface MyInterface extends Serializable, List implements Comparable {
  public int compareTo(Object o) {
    // implementation code
  }

  public void myMethod();
}


isn't an interface is...

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

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You