hamburger

Difference Between Abstract Class and Interface

By BYJU'S Exam Prep

Updated on: September 25th, 2023

The difference between the Abstract class and the Interface in Java is that the interface uses the implement keyword, whereas the abstract class uses extend keyword. It is a difficult Java interview question that typically appears in core Java interviews.  Interface and Abstract classes are used for abstraction.

We will first look at the syntactic difference between abstract class and interface in the Java programming language and then dive into each individually.

Difference between Abstract Class and Interface

The difference between Abstract class and Interface is a fundamental question for the java interview. Both of these are essentially used for abstraction. The level of abstraction is not the same for both processes. The interface gives 100% abstraction, unlike the abstract class which cannot provide complete abstraction.

Abstract class

Interface

The implementing class can only extend one abstract class.

Allows a class to implement multiple interfaces, simulating the impact of multiple inheritances.

Methods on abstract classes can be both abstract and non-abstract.

Interfaces can only have methods that are abstract, static, or default.

The abstract class supports non-final, final, non-static, and static methods and attributes.

In the interface, only final and static methods and attributes are supported.

To extend an abstract class, use the keyword ‘extend.’

The interface is implemented using the keyword implement.

Implementation Syntax: [public] class Concrete extends AbstractClass{}

Implementation Syntax: [public] class Concrete implements Interface1, Interface2, …, InterfaceN {}

What is Abstract Class?

An abstract class is beneficial when you want related classes to share a set of properties. Furthermore, an abstract class compensates for the limitations of defining method properties in an interface. One can define protected abstract methods/fields inside an abstract class, which interfaces cannot.

Difference between Abstract Class and Interface PDF

Making an abstract method private in an abstract class makes no sense. Because if an abstract method is declared private, we cannot override or access it in the abstract class’s child class, which will extend the abstract class and implement its abstract methods.

What is Interface?

An interface defines the contract for the implementing class. We can think of writing down your expectations for the class to implement your interface. In other words, an interface articulates the agreement to which you expect the implementing class to conform.

Interfaces contain a high-level description of concepts that express their disambiguated meaning whenever it is defined. An implementing class can be considered a context that clarifies the meaning of concepts defined in an interface.

Related GATE Notes
Difference Between Linear and Non-Linear Data Structures
Difference Between Hard Copy and Soft Copy Difference Between stack and queue
Difference Between overloading and overriding
Difference Between Encoder and Decoder Difference between div and span
Difference Between MAC Address and IP Address Difference between keyword and identifier
Difference Between Structure and union Difference Between Algorithm, Pseudocode, and Program
Difference Between hub and switch Difference Between Java and JavaScript
Our Apps Playstore
POPULAR EXAMS
SSC and Bank
Other Exams
GradeStack Learning Pvt. Ltd.Windsor IT Park, Tower - A, 2nd Floor, Sector 125, Noida, Uttar Pradesh 201303 help@byjusexamprep.com
Home Practice Test Series Premium