Object-oriented programming for Java - 5

Java Interface

 


1. Java Interface

To use an interface, other classes must implement it. We use the implements keyword to implement an interface.

 

1. Implementing Multiple Interfaces

Temple:

 

2. Extending an Interface

1. Extending an Interface

Similar to classes, interfaces can extend other interfaces. But the extends keyword is used for extending interfaces.

Temple:

 

2. Extending Multiple Interfaces

Temple:

 

 

3. Default Methods in Java Interfaces

To declare default methods inside interfaces, we use the default keyword.

Default methods are inherited like ordinary methods.

Temple:

 

Example: (Default Method in Java Interface)