Inheritance is for inheriting properties and having some of its own as well.

Abstract is to restrict from being instantiated.

Example:
Lets take Vehicle and VehiclePart. But Vehicle as such is very abstract and not complete. So we want Vehicle class abstract because we don't want to instantiate it directly. Car is more meaningful entity than Vehicle and car is a Vehicle. So car extends vehicle and it is not abstract.

abstract class Vehicle{
    String name;
}

abstract class VehiclePart{
    String name;
    Date expiry;
}

class Car extends Vehicle{
     List<VehicleParts> parts;
}

class RacingCar extends Vehicle{

}

class Gear extends VehiclePart{
   int numOfGears;
}

Inheritance: We need to override the method in child class

Nope. in the above example you can see Car is inheriting properties like name from Vehicle. Overriding is optional. Like RacingCar can override methods of Car and make it a little bit custom. But basically it is getting(inheriting) some properties from base class. Like all the basic properties of a car will in Car and not in RacingCar. RacingCar will have properties specific to it.


Abstract class: Put abstract keyword in method name and need to implement the method in child class

Nope. It is just to restrict its instantiation. Eg. We don't want to instantiate Vehicle object because there is no meaning to it. A vehicle has to be something like car, bus etc etc. It can't just be a vehicle. So we put abstract and restrict instantiation.

Answer from prem kumar on Stack Overflow
Top answer
1 of 7
14

Inheritance is for inheriting properties and having some of its own as well.

Abstract is to restrict from being instantiated.

Example:
Lets take Vehicle and VehiclePart. But Vehicle as such is very abstract and not complete. So we want Vehicle class abstract because we don't want to instantiate it directly. Car is more meaningful entity than Vehicle and car is a Vehicle. So car extends vehicle and it is not abstract.

abstract class Vehicle{
    String name;
}

abstract class VehiclePart{
    String name;
    Date expiry;
}

class Car extends Vehicle{
     List<VehicleParts> parts;
}

class RacingCar extends Vehicle{

}

class Gear extends VehiclePart{
   int numOfGears;
}

Inheritance: We need to override the method in child class

Nope. in the above example you can see Car is inheriting properties like name from Vehicle. Overriding is optional. Like RacingCar can override methods of Car and make it a little bit custom. But basically it is getting(inheriting) some properties from base class. Like all the basic properties of a car will in Car and not in RacingCar. RacingCar will have properties specific to it.


Abstract class: Put abstract keyword in method name and need to implement the method in child class

Nope. It is just to restrict its instantiation. Eg. We don't want to instantiate Vehicle object because there is no meaning to it. A vehicle has to be something like car, bus etc etc. It can't just be a vehicle. So we put abstract and restrict instantiation.

2 of 7
3

After java 8 you can have static and default methods in Interface. So it makes the interface much similar to abstract class.

But Still abstract class is class so we can have constructor, instance variable, getter and setter to change the state of objects. These all functionalities not provided by interface .That is main difference between interface and abstract class after java 8.

🌐
Oracle
docs.oracle.com › javase › tutorial › java › IandI › abstract.html
Abstract Methods and Classes (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)
Abstract classes are similar to interfaces. You cannot instantiate them, and they may contain a mix of methods declared with or without an implementation. However, with abstract classes, you can declare fields that are not static and final, and define public, protected, and private concrete methods.
🌐
Quora
quora.com › What-is-the-difference-between-an-abstract-class-and-an-inheritance
What is the difference between an abstract class and an inheritance? - Quora
Answer (1 of 4): Abstract class is a class that has to be inherited and cannot exist by itself. You can inherit any class, but only if it is not marked with keyword like sealed or final.
🌐
W3Schools
w3schools.com › java › java_abstract.asp
Java Abstraction
Abstract class: is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class).
🌐
Reddit
reddit.com › r/learnjava › please explain inheritance, abstract classes and interfaces
r/learnjava on Reddit: Please explain inheritance, abstract classes and interfaces
November 28, 2018 -

My daughter is in high school AP Computer Science, which is basically Java programming. Her class is online, which we now know was a mistake because she doesn't really have a teacher teaching anything. Most of her learning is done through reading an online textbook, which is not easy.

This week's concepts are:

  • inheritance

  • abstract classes

  • interfaces

She thinks she understands the ideas of these concepts, and she can read the sample code, but she doesn't think she can write her own code using these concepts. Her class has things every Wednesday, such as tests, quizzes, and coding assignments so she is trying to understand these concepts before tomorrow.

I have her coding assignment for this week, but it's really long so I'll see what specifically she needs help with. For now, if anyone can explain these 3 concepts that would be great. Thank you for any help you can provide!

🌐
Carnegie Mellon University
cs.cmu.edu › ~mrmiller › 15-121 › Slides › 18-OOP.pdf pdf
Inheritance & Abstract Classes 15-121 Fall 2020 Margaret Reid-Miller
Can inherit from only one class. ... Use super. to call the superclass ... SavingsAccount class. Take advantage of ... A ClassCastException is thrown at runtime. ... The same statement, but are calls to two different methods. Determined at runtime. ... An abstract class cannot be instantiated directly.
🌐
Pediaa
pediaa.com › home › technology › it › programming › what is the difference between abstraction and inheritance
What is the Difference Between Abstraction and Inheritance - Pediaa.Com
June 15, 2019 - The main difference between abstraction and inheritance is that abstraction allows hiding the internal details and displaying only the functionality to the users, while inheritance allows using properties and methods of an already existing class.
🌐
Difference Between
differencebetween.com › difference-between-abstract-class-and-vs-inheritance
Difference Between Abstract Class and Inheritance | Compare the Difference Between Similar Terms
June 22, 2011 - Abstract class and Inheritance ... like Java. Abstract class can be considered as an abstract version of a regular (concrete) class, while Inheritance allows new classes to extend other classes....
Find elsewhere
🌐
Medium
medium.com › nerd-for-tech › exploring-inheritance-and-abstraction-in-object-oriented-programming-1b23b68b1736
Exploring Inheritance and Abstraction in Object-Oriented Programming | by YDewz | Nerd For Tech | Medium
September 13, 2023 - Abstract classes serve as a foundation for derived classes, while inheritance allows the derived classes to acquire the properties and behaviors of the abstract class.
🌐
Smashing Magazine
smashingmagazine.com › 2019 › 11 › guide-oop-inheritance-interfaces-abstract-classes
Mastering OOP: A Practical Guide To Inheritance, Interfaces, And Abstract Classes — Smashing Magazine
This understanding applies to many things outside of the field of computing, but it is of particularly high importance for any software developer to grasp the nature of abstractions. In any case, if my words fail you, the examples in code will hopefully not. When it comes to building applications with a graphical user interface (GUI), inheritance is arguably the most important mechanism for making it possible to quickly build an application. Although there is a lesser understood benefit to using inheritance to be discussed later, the primary benefit is to share implementation between classes.
🌐
Sololearn
sololearn.com › en › Discuss › 2899594 › what-is-difference-between-abstract-class-and-inheritance
What is difference between abstract class and inheritance? | Sololearn: Learn to code for FREE!
Edit: There was differences prior to launching of Java 1.8 Where in interface we could have only abstract methods but now interface can have both default methods and abstract methods. ... Inheritance: We need to override the method in child class We use Inheritance in case of Parent-Child relationship[Child can have all functionalities which Parent have and can add more functionality to itself too] And we use Abstract class(In java) for a partial set of default implementations of methods in a class, which also can be implemented by simple Inheritance.
Top answer
1 of 3
6

Inheriting from a base class is useful if you want to use the same code as the base class and extend it with extra functionality.

Vitual and abstract are related to this. You can make a virtual method with a base implementation. A descendant class can (optionally) change or add to this implementation. An abstract class is a base class that is incomplete in itself. An abstract method is declared, but has no implementation yet. A descendant class must provide an implementation. This is useful if the base class implements a flow, but a part of that flow needs to be implemented by another class. The base class needs to be able to call that part, which is where declaring an abstract method comes in sight.

Interfaces are a different story. An interface is a contract about which methods exist in a class, but they can be implemented by two completely unrelated classes. This is convenient, because you can make small interfaces for small pieces of functionality. For example, something that can be saved can implement ISavable, which just enforces the existence of the method 'Save'. Two completely different classes can implement this, allowing for instance a Save All functionality to just save everything that can be saved.

Multiple inheritance is a specific language feature, that is not available in many languages, although in many languages you can have a similar effect by using interfaces and the delegate design pattern.

2 of 3
0

it depends on your own style.

In fact, a class which inherits from an abstract class has to use ALL attributes and methods of it - it is nearly impossible to create a clean architecture with many levels of inheritance.

The main advantage of interfaces is the flexibility - you can implement much of them but do not have to change the internal structure of your class to implement them.

In most cases, it is best practice to use interfaces, except in some software patterns like compositum or strategy pattern.

But at the end it is your decision - you have to choose the type of inheritance you want in your project.

Interfaces help you to gain flexibility, abstract classes bring more cohesiveness to your architecture because they group classes that are similar together. --> you can reuse your code of the abstract classes in its subclasses

🌐
GeeksforGeeks
geeksforgeeks.org › java › difference-between-abstract-class-and-interface-in-java
Difference Between Abstract Class and Interface in Java - GeeksforGeeks
It is a total abstraction, all methods declared within an interface must be implemented by the class(es) that implements this interface. A class can implement more than one interface. It is called multiple inheritances.
Published   July 23, 2025
🌐
Colorado State University
cs.colostate.edu › ~cs163 › .Summer20 › labs › 16AbstractClasses
Lab 16 - Abstract Classes and Inheritance | CS 163/4: Java Programming (CS 1)
July 8, 2020 - An Abstract class acts as a way ... a single super class which has key traits necessary for multiple subclasses, but unlike normal inheritance an Abstract class by itself cannot be an Object....
🌐
Northeastern
course.khoury.northeastern.edu › cs2510h › lecture9.html
Lecture 9: Abstract classes and inheritance
We cannot plausibly construct an abstract shape— · we don’t have enough information about it— · and a real shape will have other fields to represent that additional information. Each of the three classes will become a subclass of the class AShape and will inherit all fields defined in its super class: Even though we do not see the fields loc and color anywhere in the class definitions, the class definition starts with ·
🌐
Saylor Academy
learn.saylor.org › mod › book › view.php
Objects and Classes: Inheritance, Polymorphism, and Abstract Classes | Saylor Academy | Saylor Academy
They create a class hierarchy that ... objects. Whereas Java has simple inheritance (a subclass can extend one superclass), C++ has multiple inheritance ( a subclass can extend 2 or more superclasses)....
🌐
Reddit
reddit.com › r/javahelp › when do you use inheritance and abstract classes?
r/javahelp on Reddit: When do you use inheritance and abstract classes?
July 18, 2021 -

In my work's codebase, we very rarely us inheritance if at all in our new modern code. In our legacy system there's some inheritance which is very ugly and hard to read. To me, inheritance opens the door to spaghetti code where calling an object's method calls a superclass' implementation of it, and makes it harder to test.

I wanted to know if and when you use inheritance, and in what scenarios? Why would you use inheritance instead of interfaces + composition?