+ 2
I'm confused about interface in Java , can somebody clarify me ???
Interface in java, Why there is no method in interfaces???
3 ответов
+ 2
Typically there are some methods in interfaces, but it can be without method bodies
Interface Name {
type method1;
type2 metho2;
}
method bodies are defined by implementions of interfaces
+ 2
Interface methods are by default abstract so the class(concrete) implementing it must agree to the contract of providing implementation for all the methods of the interface.
Apart from abstract methods interface also has default and static methods which can be declared and defined within the interface itself and it is completely legal.
interface A{
void show();
void print();
default void execute(){
//do something
}
static void terminate(){
//do something
}
}