You are on page 1of 2

What is default method?

default method is an interface class that has implementation body.

fo eg :

interface Example{
abstract void m1()
}

class Sample implements Example{

public void m1{


}

class xyz implements Example{


public void m2{
}
}
=======================================

In the absence of default method : there is interface limitation we wil have to see

for example , if we are going to add additional new feature in interface then all
the different implementation will have must implemented that method for sue.

But there would be possibility that some of the implementation class dont require
that features.

========================================

So, this is the reason why default method came into picture.

Why default method?

>>For adding new functonality to an existing interface without beaking/disturbing


existing implementation classes.

>>Using default method feature we can add new methods in the interface by not
forcing subclasses to implement those new methods.

>>So we can say with default method feature implementation class programmers are
free from implementing new methods.They(implementation class programmers) can
continue with old implementation and by reusing the functionality given in the
default method in the interface. In future they(implementation class programmers)
can provide implementation as per their requirement.

You might also like