What is super-interface is java? what is the purpose of super-interface?
-
Do you mean "super()"? super in java references the base object of the class.Zack– Zack2009年06月30日 18:19:06 +00:00Commented Jun 30, 2009 at 18:19
-
2@DB, I think it's ok to ask basic question that could be looked up on SO. See stackoverflow.com/questions/1003841/… by Jeff.Eugene Yokota– Eugene Yokota2009年06月30日 18:23:54 +00:00Commented Jun 30, 2009 at 18:23
-
Thank god I didn't post an answer because I would've been wrong, lol. I was thinking super-classes. But I learnt something new -- super-interfaces!Zack– Zack2009年06月30日 18:26:05 +00:00Commented Jun 30, 2009 at 18:26
-
1Goggling "java super interface site:oracle.com" turned up nothing that looked promising.Raedwald– Raedwald2013年07月20日 20:17:55 +00:00Commented Jul 20, 2013 at 20:17
-
4I did use Google. Google brought me here.m24p– m24p2014年09月09日 20:59:13 +00:00Commented Sep 9, 2014 at 20:59
6 Answers 6
Here's an example:
public interface A {
void doSomething();
}
public interface B extends A {
void doSomethingElse();
}
In this example, A is a superinterface of B. It's like being a superclass. Any class implementing B now also implements A automatically, and must provide an implementation of both doSomething() and doSomethingElse().
1 Comment
The term superinterface has slightly different uses depending on the context of (a) interfaces only, and (b) classes, as described below:
(a) given interfaces A, and B, when B extends A then A is a superinterface of B (the explanation given above by Tom.)
see jls8, 8.1.5
(b) given class X, and interface C, when X implements C, then C is a direct superinterface of X.
see jls8, 9.1.3
The second case here is not clear from any of the prior explanations. That is, in case (b) there isn't any requirement for a hierarchical chain of interfaces in order to use the term superinterface.
Comments
If you have
public interface Bar extends Foo
then Foo would be the super-interface of Bar. This declares that all instances of Bar are also instances of Foo and can be treated as such, so you could pass a Bar instance wherever you needed to pass a Foo, etc.
Comments
Basically, when an interface extends from other interface, it is forcing the class that implements it to implement methods in both interfaces.
If an extends clause is provided, then the interface being declared extends each of the other named interfaces and therefore inherits the member types, methods, and constants of each of the other named interfaces. These other named interfaces are the direct superinterfaces of the interface being declared. Any class that implements the declared interface is also considered to implement all the interfaces that this interface extends.
You can have method overriding also :)
http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html
Comments
Interfaces in Java can extend one another, so that the extending interface supports all the things provided by the parent and the things it provides itself. For example, a Set has unique operations, but also supports everything that a Collection does.
The interfaces from which you are extending are considered super-interfaces. Note that an interface can extend multiple interfaces and therefore has multiple super-interfaces.
4 Comments
when you have 2 interfaces with some related (same) field or methods. you should use one as superInterface which the second will extend, you shouldn't duplicate it. this is because simplicity and clarity to see what is going on exactly.