Interface in Java: How to define, implement, and extend interfaces?

Interface is used to specify a set of methods which could be used by classes. They work like a class except they don’t have instance variables and instance methods don’t have a body.  An interface can be implemented by any number of classes and a single class can implement any number of interfaces. Thus, an interface is just the definition of a method, and how it would be used is determined by the class. Interface is yet another concept which uses polymorphism. In an interface variables are final and static by default.


access interface name {

return_type method_name1(parameter_list);

return_type method_name2(parameter_list);

type final_variable_name1 = value;

type final_variable_name2 = value;

return_type method_nameN(parameter_list);

type final_variable_nameN = value;


Implementation of an interface by a class:

access class classname [extends superclass]

[implements interface [,interface…]] {

body of class;


Just like a class, an interface can also be extended:

For Example:

interface Int1 {

void meta();

void metb();


interface Int2 extends Int1 {

void metc();

void metd();


Leave a Reply