Abstract Class Vs. Interface: Explore the Difference between Abstract Class and Interface in Java
The Abstract class and Interface both are used to have abstraction. An abstract class contains an abstract keyword on the declaration whereas an Interface is a sketch that is used to implement a class. Explore more differences between abstract class and interface in java.
Ultimate Guide to Kickstart your GATE Exam Preparation
Download the e-book now
What is an Abstract Class?
A class that contains an abstract keyword on the declaration is known as an abstract class. It is necessary for an abstract class to have at least one abstract method. It is possible in an abstract class to contain multiple concrete methods.
What is an Interface?
An interface is a sketch that is useful to implement a class. The methods used in the interface are all abstract methods. The interface does not have any concrete method.
Difference between Abstract Class and Interface in Java
|1.||An abstract class can contain both abstract and non-abstract methods.||Interface contains only abstract methods.|
|2.||An abstract class can have all four; static, non-static and final, non-final variables.||Only final and static variables are used.|
|3.||To declare abstract class abstract keywords are used.||The interface can be declared with the interface keyword.|
|4.||It supports multiple inheritance.||It does not support multiple inheritance.|
|5.||The keyword ‘extend’ is used to extend an abstract class||The keyword implement is used to implement the interface.|
|6.||It has class members like private and protected, etc.||It has class members public by default.|
Keep learning and stay tuned to get the latest updates on GATE Exam along with GATE Eligibility Criteria, GATE 2023, GATE Admit Card, GATE Application Form, GATE Syllabus, GATE Cut off, GATE Previous Year Question Paper, and more.
- Difference between Abstraction and Encapsulation in Java
- Difference between Aggregation and Composition in Java
- Difference between Hashset and Treeset in Java
- Difference between == and .equals() method in Java
- Difference between Primitive and Object Data Types in Java
- Difference between Stack and Heap Memory in Java
- Difference between Throw and Throws in Java