Computer Science, asked by priyabujji5314, 11 months ago

Why do we use interfaces in Java?

Answers

Answered by mrsolver2912
0

Like a class, an interface can have methods and variables, but the methods declared in interface are by default abstract (only method signature, no body).

Interfaces specify what a class must do and not how. It is the blueprint of the class.

An Interface is about capabilities like a Player may be an interface and any class implementing Player must be able to (or must implement) move(). So it specifies a set of methods that the class has to implement.

If a class implements an interface and does not provide method bodies for all functions specified in the interface, then class must be declared abstract.

Similar questions