Java error "interface methods cannot have body" occurs when body of the method within an interface is defined.
See the code below:
Here the method myMethod has body starting at the symbol { and ending at }. An interface can have abstract methods (method without any body). The class that implements the interface defines the body of the interface methods.
So to remove the error, the method signature/header will end by ; (semi colon) and there will be no body section for the method. Below is the correct code:
See the code below:
public interface MyInterface
{
public void myMetod()
{
}
}
Here the method myMethod has body starting at the symbol { and ending at }. An interface can have abstract methods (method without any body). The class that implements the interface defines the body of the interface methods.
So to remove the error, the method signature/header will end by ; (semi colon) and there will be no body section for the method. Below is the correct code:
public interface MyInterface
{
public void myMetod();
}
very helpful
ReplyDelete