interface implements interfaces?
I think I am overlooking a very basic concept here... Why can't we have an Interface that implements an Interface? Or is it that Interfaces should always be top level, there cannot be an Interface somewhere in between a hierarchy tree?
Note: Text content in the code blocks is automatically word-wrapped
interface ParentInterface{
void myMethod();
}
interface SubInterface implements ParentInterface{
void anotherMethod();
void myMethod();
}
|
Ans: i) Interface extends another interface but not implements it, because interface will not contain the implementation (you cannot provide implementation in the interface). So you can just extend it but not implement it.
Ans:ii) Implements denotes defining an implementation for the methods of an interface. However interfaces have no implementation so that's not possible. An interface can however extend another interface, which means it can add more methods and inherit its type.
Note: Text content in the code blocks is automatically word-wrapped
interface ParentInterface{
void myMethod();
}
interface SubInterface extends ParentInterface{
void anotherMethod();
}
No comments:
Post a Comment