![]() Interfaces appear in packages, and their corresponding bytecode file must. The byte code of an interface appears in a. ![]() java extension, with the name of the interface matching the name of the file. An interface can contain any number of methods. He asked me for a more practical response, explaining when I would choose an abstract class over an interface, using practical examples. An interface is similar to a class in the following ways. However, the interviewer was not satisfied, and told me that this description represented " bookish knowledge". Java abstract class should be extended using keyword “extends”.Īn interface can extend another Java interface only, an abstract classĬan extend another Java class and implement multiple Java interfaces.Ī Java class can implement multiple interfaces but it can extend only A Java abstractĬlass can have the usual flavours of class members like private,Ī Java interface should be implemented using keyword “implements” A Members of a Java interface are public by default. AnĪbstract class may contain non-final variables. Variables declared in a Java interface are by default final. It's difficult to tell whether it is appropriate for your specific case, but there's nothing wrong using the practice in principle. Instance methods that implements a default behaviour. Interface inheritance is an excellent tool, though you should only use it when interface B is truly substitutable for interface A, not just to aggregate loosely-related behaviors. Methods of a Java interface are implicitly abstractĪnd cannot have implementations. In one of my interviews, I have been asked to explain the difference between an Interface and an Abstract class.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |