Difference Between Abstract Class and Interface

By Priyanshu Vaish|Updated : October 4th, 2022

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 CopyDifference Between stack and queue
Difference Between overloading and overriding
Difference Between Encoder and DecoderDifference between div and span
Difference Between MAC Address and IP AddressDifference between keyword and identifier
Difference Between Structure and unionDifference Between Algorithm, Pseudocode, and Program
Difference Between hub and switchDifference Between Java and JavaScript

Comments

write a comment

FAQs on Difference Between Abstract class and Interface

  • The difference between Abstract class and interface regarding the keyword is that the abstract class uses the keyword extend whereas the interface uses the keyword implement in the java programming languages.

  • The difference between Abstract class and interface regarding syntax is that the syntax of  abstract class is:

    [public] class Concrete extends AbstractClass{}

    And the syntax of the interface class is:

    [public] class Concrete implements Interface1, Interface2, ..., InterfaceN {}

  • In Java 8, the main difference between abstract class and interface is that an abstract class is a class and an interface is an interface. A class can have a state that can be changed by non-abstract methods, but an interface cannot because it cannot have instance variables.

  • An abstract class is used when you want to provide a common, implemented functionality across all component implementations. Abstract classes allow you to partially implement your class, whereas interfaces have no implementation for any members.

  • If a class's method is private, it cannot be accessed outside of the current class, not even from its child classes. However, you cannot use an abstract method from the same class; instead, you must override it from a subclass and use it. As a result, the abstract method cannot be made private.

Follow us for latest updates