| 1. |
What is the difference between an interface and abstract class in Java? |
||||||||||||||||
|
Answer» For classes and methods, the abstract keyword is a non-access MODIFIER. An abstract class is a special kind of class that can't be used to create objects (to access it, it must be inherited from another class). Talking about an abstract method, it has no body and it can only be used in an abstract class. The subclass provides the body (inherited from). In Java, an interface is a blueprint for a class. It features abstract methods and static constants. In Java, the interface is a means of achieving abstraction. The Java interface can only have abstract methods, not method bodies. In Java, it is used to achieve abstraction as well as MULTIPLE inheritances. To put it another way, interfaces can have abstract methods and variables. It isn't allowed to have a method body. The differences between the two have been TABULATED below:
|
|||||||||||||||||