Sunday, June 22, 2014

Interface (Object-Oriented Programming)

Interface (Object Oriented Programming) is a blueprint of a class. They are contract between programmer and programming language.
In Java programming language, an interface is a reference type, similar to a class that can contain only constant, method signatures, and nested type. It is a mechanism to achieve abstraction in Java. There are no method body. Interface cannot be instantiated, they can only be implemented by classes or extended by other interface. One interface can extend and one class can implements more than one interface simultaneously.

Why we Use Interface (Object-Oriented Programming):-

1. Achieve abstraction.
2. Support the functionality of multiple inheritances.

Defining an Interface (Object-Oriented Programming):-

An interface declaration consist of modifiers, the keyword interface, its name, a comma separated list of parent interface (if any), and the its body.

Simple Example of Interface in Java: -

Output:-

Sum is =170
Sub is =30

No comments:

Post a Comment