examples of interface in java programming

0

What is meant by Interface?

Answer: Multiple inheritances cannot be achieved in java. To overcome this problem the Interface concept is introduced.

An interface is a template which has only method declarations and not the method implementation.

Example:

Public abstract interface IManupulation{ //Interface declaration
Public abstract void add();//method declaration
public abstract void subtract();
}
All the methods in the interface are internally public abstract void.
All the variables in the interface are internally public static final that is constants.
Classes can implement the interface and not extends.
The class which implements the interface should provide an implementation for all the methods declared in the interface.
public class Manupulation implements IManupulation{ //Manupulation class uses the interface
Public void add(){
}
Public void subtract(){
}
}

All Contributions

total contributions (0)

New to examplegeek.com?

Join us