top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the use of Interface default method in Java 8, how can it be useful in real life applications?

+1 vote
114 views
What is the use of Interface default method in Java 8, how can it be useful in real life applications?
posted Jun 20, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Java 8 introduces “Default Method” or (Defender methods) new feature, which allows developer to add new methods to the interfaces without breaking the existing implementation of these interface. It provides flexibility to allow interface define implementation which will use as default in the situation where a concrete class fails to provide an implementation for that method.

Let consider small example to understand how it works:

public interface oldInterface {
    public void existingMethod();
        default public void newDefaultMethod() {
        System.out.println("New default method"
              " is added in interface");
    }
}

For More Information Please click here

answer Jul 1, 2015 by Karthick.c
...