DEV Community

Saravanan B
Saravanan B

Posted on

Core Java - Interface

Interface Fully Abstract methods.

public interface Car {
    void go();
    void stop();
}
Enter fullscreen mode Exit fullscreen mode
public class Honda implements Car{

    @Override
    public void go() {
        System.out.println("Implemented go method");
    }

    @Override
    public void stop() {
        System.out.println("Implemented stop method");
    }

}
Enter fullscreen mode Exit fullscreen mode
public class Test {
    public static void main(String[] args) {
        Honda h = new Honda();
        h.go();
        h.stop();
    }
}
Enter fullscreen mode Exit fullscreen mode

An interface is a contract whereas Abstract method contains partial implementation.

An interface is by default public abstract method.

Variable in interface is public static final and should be initialized.

cannot define blocks and constructor.

Top comments (0)