Java interfaces and polymorphism

Java interface

An interface in Java is an abstract type that defines a set of method signatures. It provides a way to define the agreement between classes, that is, which methods the class should implement. In this tutorial, we will explore the use and implementation of interfaces in Java.

Step 1: Define the interface

We first need to define an interface. Interfaces interfaceare declared using keywords and define the methods that need to be implemented.

public interface Shape {
   
    
    
    double getArea();
    double getPerimeter();
}

In the example above, we defined a class namedShape

Guess you like

Origin blog.csdn.net/IamBird/article/details/131065238