Interfaces in JAVA

Anjana Dinethra
2 min readMar 23, 2021

--

part 01

What is an Interface,

An inteface is a collection of methods, that a particular class that implements interface MUST implement.

interface itself is a abstract class.So that means there is no code for the methods inside the interface.

Declaring a interface,

ex:

when we are declaring the interface name, it is better to start with a “I” so then we can clearly notice the interfaces.

inside the interfaces we are just creating the method signatures. No actual code inside the methods, but we can use parameters.

ex:

those above methods are only the signatures of the actual methods.we dont put code inside those interface methods because they are abstract methods.

the access modifiers of the interface methods are public by default,as they shoud be.So no need to specify the access modifiers in front of the methods.

We can create variables inside the interfaces as well.They are public static and final by default.

Implementing interface for a class,

when implementing a interface we need to use the keyword implements.

ex:

inside the above method we MUST definetly include all the interface methods because we are implementing previous interface IVehicle for this Car class.If we are not including those methods in Car class after implementing IVehicle then the Car class should be a abstract class.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Anjana Dinethra
Anjana Dinethra

Responses (1)

Write a response