14 Interfaces

An interface is a group of related methods with empty bodies. In other words, it is a collection of abstract methods. An interface is not a class. A class implements an interface to inherit the abstract method of the interface.


The following code shows an interface Cars, that has method make() and price().


Cars Interface



The following steps show class Nissan which implements Cars interface and define its abstract method make() and price().



14.1 | Create a new class in Eclipse


1. Create a new class in Eclipse as defined in the previous post.

2. Provide reference of Cars interface as shown in below screen.
3. Click on Finish button.


Nissan Class implements Cars interface




14.2 | Created Nissan Class


Created Nissan class looks like below screen





The following code shows class Nissan which implements Cars interface and defines its abstract method make() and price().


Nissan Class



The below screen is the output of the above codes.








No comments: