Abstract Class & Interface
Abstract Class: Abstract class is same as other class except that it can not be instantiated .
It is generally to write the common functionality in the parent class.
It can have abstract and non-abstract method.
Abstract class can have final, non-final, static and non-static variables.
It can also implement interface and define the methods of interface, but it can not be instantiated.
Interface: An interface in java is a blueprint of a class. It has static constants and abstract methods only. Interface basically defines the contract for a class to implement.
It is a mechanism to achieve fully abstraction. There can be only abstract methods in the java interface not method body.
It cannot be instantiated like abstract class.
A class can extend multiple Interfaces. An interface can extend multiple Interfaces.
Abstract Class: Abstract class is same as other class except that it can not be instantiated .
It is generally to write the common functionality in the parent class.
It can have abstract and non-abstract method.
Abstract class can have final, non-final, static and non-static variables.
It can also implement interface and define the methods of interface, but it can not be instantiated.
Interface: An interface in java is a blueprint of a class. It has static constants and abstract methods only. Interface basically defines the contract for a class to implement.
It is a mechanism to achieve fully abstraction. There can be only abstract methods in the java interface not method body.
It cannot be instantiated like abstract class.
A class can extend multiple Interfaces. An interface can extend multiple Interfaces.
| Abstract class | Interface |
|---|---|
| 1) Abstract class can have abstract and non-abstract methods. | Interface can have only abstract methods. |
| 2) Abstract class doesn't support multiple inheritance. | Interface supports multiple inheritance. |
| 3) Abstract class can have final, non-final, static and non-static variables. | Interface has only static and final variables. |
| 4) Abstract class can have static methods, main method and constructor. | Interface can't have static methods, main method or constructor. |
| 5) Abstract class can provide the implementation of interface. | Interface can't provide the implementation of abstract class. |
Comments
Post a Comment