I have an idea. But I am not sure if it is the right answer. Can I divide these 4 methods into 2 interface? Then I can only implement the wanted 2 methods.:Directly implement those two methods and leave the remaining two in a new class which can implements the given interface.:It is not possible.The rule of the interface is that we have to overide all the methods present in it.If we fail, the complier will show the error. We have the concept of adapter classes in java. In this adapter classes, if an listener interface has many methods in that case we can use the corresponding adapter class to implement only the requried methods. But for user defined interfaces there is no such option.So it is not possible.:Hi...:yes, we can implement this concept as interface implement in class by giving body of require methods and leave blank to other two method as::when a class implements one interface it must implement(define) all the methods which have declared in the interface.:a class must implement all the methods in an interface or be an abstract class.
Category:Java Interview Questions
No comments:
Post a Comment