Reputation: 71
Actually, i have attended the interview. They ask me,
There is a three functions in interface. overridden class only need to override only one function. how can you achieve this?
Anyone know how to do this?
Upvotes: 2
Views: 1413
Reputation: 393851
To expand on the other answer, an abstract method that implements an interface can choose to implement only some of the methods of that interface, leaving the implementation of the rest of the methods to its concrete sub-classes.
In Java 8 you can do it even with concrete classes, as interfaces can have default implementations for some of their methods. Therefore, only the methods that don't have default implementations must be implemented by concrete classes that implement the interface.
Upvotes: 6
Reputation: 878
You can declare the class implementing that interface as abstract
.
But the class extending that abstract class has to implement all the methods declared in that interface that have not been overridden in the abstract class.
Upvotes: 1