Core Java - Interface

saravananb15

Saravanan B

Posted on February 14, 2023

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.

💖 💪 🙅 🚩
saravananb15
Saravanan B

Posted on February 14, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related