1.

What is a default method? Why this design change has been done?

Answer»

In the earlier versions of Java (up to 1.7), the interface was DESIGNED to have only method signatures. From Java 8 the interface is now able to CONTAIN method implementation as well. These methods should be marked with default keyword and are called default methods of an interface. This means it is not mandatory to override the default methods in the implementing classes. When an interface is widely used by many applications, it was very DIFFICULT to add a new method in the same, because, it can break the code. The implementers need to change their code in many places. To overcome this COMPLEXITY and make interfaces backward compatible this change has been introduced. public interface SHAPE

default double area() {  return 0.0; } default double volume() {  return 0.0; } }


Discussion

No Comment Found