Abstract classes are "half-implementations" of a class. They can be partially implemented with some generic functionality, but leave part of the implementation to the inheriting classes. You could have an abstract class called Animal that has implemented some generic behavior/values such as Age, Name, SetAge(...). You can also have methods that are not implemented (they are abstract), much like an interface.

Interfaces are simply contracts that specify behaviors that should be available for a class. You could have an interface such as IWalker that requires public method Walk(), but no specifics on how it is implemented.

Answer from Blixt on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › abstract-classes-in-java
Abstract Class in Java - GeeksforGeeks
In Java, we can have an abstract class without any abstract method. This allows us to create classes that cannot be instantiated but can only be inherited. It is as shown below as follows with help of a clean java program.
Published   July 23, 2025
🌐
W3Schools
w3schools.com › java › java_abstract.asp
Java Abstraction
Java Examples Java Compiler Java Exercises Java Quiz Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... Data abstraction is the process of hiding certain details and showing only essential information to the user. Abstraction can be achieved with either abstract classes or interfaces (which you will learn more about in the next chapter).
Discussions

oop - What are some practical examples of abstract classes in java? - Stack Overflow
When and why should abstract classes be used? I would like to see some practical examples of their uses. Also, what is the difference between abstract classes and interfaces? More on stackoverflow.com
🌐 stackoverflow.com
[Java] Can anyone give an example of an abstract class, and why it is important to use?
public abstract class Character {
    ...
    public abstract void attack();
    ...
}

public class Warrior extends Character {
    ...
    public void attack() { 
        // do something specific to warriors
    }
    ...
}

public class Archer extends Character {
    ...
    public void attack() { 
        // do something specific to archers
    }
    ...
}

And after this, you can have a List<Character>, and call attack regardless of what the actual class is. Abstract classes, unlike interfaces are allowed to have their own fields. They are basically like "rich" interfaces.

More on reddit.com
🌐 r/learnprogramming
7
1
May 21, 2013
java - Abstract Class:-Real Time Example - Stack Overflow
You should be able to cite at least one from the JDK itself. Look in the java.util.collections package. There are several abstract classes. You should fully understand interface, abstract, and concrete for Map and why Joshua Bloch wrote it that way. ... The best example of an abstract class ... More on stackoverflow.com
🌐 stackoverflow.com
Can you give an example of why exactly a Java abstract method cannot exist in a non-abstract class? - Stack Overflow
I'd like a real-world type example that illustrates why exactly a Java abstract method cannot exist in a non-abstract class. I appreciate the reasons why that can't happen - abstract classes forcing More on stackoverflow.com
🌐 stackoverflow.com
🌐
Programiz
programiz.com › java-programming › abstract-classes-methods
Java Abstract Class and Method (With Example)
The major advantage of hiding the working of the brake is that now the manufacturer can implement brake differently for different motorbikes, however, what brake does will be the same. Let's take an example that helps us to better understand Java abstraction. abstract class MotorBike { abstract void brake(); } class SportsBike extends MotorBike { // implementation of abstract method public void brake() { System.out.println("SportsBike Brake"); } } class MountainBike extends MotorBike { // implementation of abstract method public void brake() { System.out.println("MountainBike Brake"); } } class Main { public static void main(String[] args) { MountainBike m1 = new MountainBike(); m1.brake(); SportsBike s1 = new SportsBike(); s1.brake(); } }
🌐
Oracle
docs.oracle.com › javase › tutorial › java › IandI › abstract.html
Abstract Methods and Classes (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)
You want to take advantage of multiple inheritance of type. An example of an abstract class in the JDK is AbstractMap, which is part of the Collections Framework.
🌐
DataCamp
datacamp.com › doc › java › abstract
abstract Keyword in Java: Usage & Examples
You must create an instance of a subclass that implements all abstract methods. Use Abstract Methods for Interfaces: If you have a class that will serve as a base with methods that must be overridden, use abstract methods to enforce this contract.
🌐
Medium
medium.com › @YodgorbekKomilo › abstract-classes-in-java-a-comprehensive-guide-with-examples-2ec88ed0f80b
Abstract Classes in Java: A Comprehensive Guide with Examples | by Yodgorbek Komilov | Medium
November 24, 2024 - Abstract classes in Java are a key component of object-oriented programming. They provide a way to define a blueprint for classes, allowing shared functionality while enforcing a structure for subclasses. This post will explore abstract classes, their usefulness, and how to implement them with examples.
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › abstract-class-in-java
Abstract Class in Java | DigitalOcean
August 3, 2022 - Note that subclass Employee inherits the properties and methods of superclass Person using inheritance in java. Also notice the use of Override annotation in Employee class. Read more for why we should always use Override annotation when overriding a method. abstract keyword is used to create an abstract class in java.
🌐
Medium
hemanthcse1.medium.com › abstract-class-in-java-6e825d671c10
Abstract class in Java. An abstract class in Java is a class… | by Hemanth Kumar N V | Medium
June 2, 2024 - Abstract classes can have constructors, which can be used to initialize fields. However, you cannot instantiate an abstract class directly. Instead, the constructor of the abstract class is called when a subclass is instantiated. In the Vehicle example, the constructor initializes the name field.
🌐
Medium
medium.com › @nakulmitra2114 › abstract-classes-in-java-a0bd4bb2c7d9
Abstract Classes in Java. In Java, abstraction is one of the core… | by Nakul Mitra | Medium
September 15, 2024 - One of the primary ways to achieve abstraction in Java is through the use of abstract classes and interfaces. ... In this blog, we’ll focus on abstract classes — their definition, usage, and how they differ from interfaces. We’ll also explore practical examples to demonstrate how abstract ...
🌐
Baeldung
baeldung.com › home › java › core java › abstract classes in java
Abstract Classes in Java | Baeldung
January 8, 2024 - Let’s keep in mind that all these scenarios are good examples of full, inheritance-based adherence to the Open/Closed principle. Moreover, since the use of abstract classes implicitly deals with base types and subtypes, we’re also taking advantage of Polymorphism. Note that code reuse is a very compelling reason to use abstract classes, as long as the “is-a” relationship within the class hierarchy is preserved. And Java 8 adds another wrinkle with default methods, which can sometimes take the place of needing to create an abstract class altogether.
🌐
I'd Rather Be Writing
idratherbewriting.com › java-abstract-methods
Java: Abstract classes and abstract methods | I'd Rather Be Writing Blog and API doc course
January 2, 2015 - Consequently, we don’t want anyone to create an instance of our Mammal class, because that would be bad modeling. Java lets developers declare that a class should never have an instance by using the abstract keyword. In Java, abstract means that the class can still be extended by other classes but that it can never be instantiated (turned into an object). Returning to our example, we can have Mammal be abstract (because there’s no such thing as a generic mammal) and still have Cat, Dog, and Mouse extend Mammal (because cats, dogs, and mice are mammals).
🌐
w3resource
w3resource.com › java-exercises › index-abstract.php
Java Abstract Classes: Exercises, Practices, Solutions
May 16, 2025 - Create subclasses for Glockenspiel and Violin that extend the Instrument class and implement the respective methods to play and tune each instrument. ... 10. Write a Java program to create an abstract class Shape2D with abstract methods draw() ...
Top answer
1 of 5
29

A good example of real time found from here:-

A concrete example of an abstract class would be a class called Animal. You see many animals in real life, but there are only kinds of animals. That is, you never look at something purple and furry and say "that is an animal and there is no more specific way of defining it". Instead, you see a dog or a cat or a pig... all animals. The point is, that you can never see an animal walking around that isn't more specifically something else (duck, pig, etc.). The Animal is the abstract class and Duck/Pig/Cat are all classes that derive from that base class. Animals might provide a function called "Age" that adds 1 year of life to the animals. It might also provide an abstract method called "IsDead" that, when called, will tell you if the animal has died. Since IsDead is abstract, each animal must implement it. So, a Cat might decide it is dead after it reaches 14 years of age, but a Duck might decide it dies after 5 years of age. The abstract class Animal provides the Age function to all classes that derive from it, but each of those classes has to implement IsDead on their own.

A business example:

I have a persistance engine that will work against any data sourcer (XML, ASCII (delimited and fixed-length), various JDBC sources (Oracle, SQL, ODBC, etc.) I created a base, abstract class to provide common functionality in this persistance, but instantiate the appropriate "Port" (subclass) when persisting my objects. (This makes development of new "Ports" much easier, since most of the work is done in the superclasses; especially the various JDBC ones; since I not only do persistance but other things [like table generation], I have to provide the various differences for each database.) The best business examples of Interfaces are the Collections. I can work with a java.util.List without caring how it is implemented; having the List as an abstract class does not make sense because there are fundamental differences in how anArrayList works as opposed to a LinkedList. Likewise, Map and Set. And if I am just working with a group of objects and don't care if it's a List, Map, or Set, I can just use the Collection interface.

2 of 5
10

Here, Something about abstract class...

  1. Abstract class is an incomplete class so we can't instantiate it.
  2. If methods are abstract, class must be abstract.
  3. In abstract class, we use abstract and concrete method both.
  4. It is illegal to define a class abstract and final both.

Real time example--

If you want to make a new car(WagonX) in which all the another car's properties are included like color,size, engine etc.and you want to add some another features like model,baseEngine in your car.Then simply you create a abstract class WagonX where you use all the predefined functionality as abstract and another functionalities are concrete, which is is defined by you.
Another sub class which extend the abstract class WagonX,By default it also access the abstract methods which is instantiated in abstract class.SubClasses also access the concrete methods by creating the subclass's object.
For reusability the code, the developers use abstract class mostly.

abstract class WagonX
{
   public abstract void model();
   public abstract void color();
   public static void baseEngine()
    {
     // your logic here
    }
   public static void size()
   {
   // logic here
   }
}
class Car extends WagonX
{
public void model()
{
// logic here
}
public void color()
{
// logic here
}
}
Top answer
1 of 5
1

An abstract class means that the class can't be directly instantiated. If a class has an abstract method, then it can't be directly instantiated since there would be no definition for that method. Therefore, any class with an abstract method IS an abstract class that can't be instantiated. Java simply makes you label it as such.

2 of 5
0

One of the key differences between an abstract class and a non-abstract class is the fact that you cannot create an instance of an abstract class. This prevents a situation where a method with no definition gets called.

So if we had the following abstract class:

abstract class Elephant {    // abstract class

    public String getName() {
        return "Ollie";
    }

    public abstract void walk();   // abstract method

}

Then the following would be illegal:

Elephant e = new Elephant();   // error

Because Elephant is abstract and it cannot be instantiated.

But say for argument sake, that we make Elephant non-abstract but it is allowed to still have the abstract method walk(). i.e. we change the definition of Elephant to:

class Elephant {    // non-abstract class

    public String getName() {
        return "Ollie";
    }

    public abstract void walk();    // abstract method

}

Now what should happen if I do the following:

Elephant e = new Elephant();   // legal since Elephant is non-abstract
e.walk();   // oops, we didn't define this anywhere

Java compiler won't allow this. You could argue that there are other ways to handle a situation like this, but this simply how the Java language has decided to implement the feature.

🌐
Reddit
reddit.com › r/learnjava › interfaces & abstract classes in java
r/learnjava on Reddit: Interfaces & Abstract Classes in Java
May 14, 2022 -

I should preface this post with this: I'm a beginner in Java.

I don't get interfaces. Yes, they enable us to do multiple inheritance, but that's it. I don't see any other use they have (please do let me know some of the uses they exclusively have).

As far as I know, anything I can do with interfaces, I can do with abstract classes (other than multiple inheritance of course). Should I use interfaces only when I need to do multiple inheritance?

Very sorry if I offended any of you interface lovers our there.

Thanks

Edit: Would really appreciate it if you could explain to me why all the attributes and methods in interfaces are public by default.

🌐
Quora
quora.com › How-do-I-run-an-abstract-class-in-Java
How to run an abstract class in Java - Quora
Answer (1 of 2): TL;DR: You can't. Longer version: Abstract classes and interfaces enable the developer to define how a type of class, that is concrete classes that implement the interface or are subclasses of the abstract class, can be interacted with, and, in the case of abstract classes, all...
🌐
Medium
medium.com › @ashfaque-khokhar › abstract-classes-and-methods-738ef810e99d
Abstract Classes and Methods. In Java, abstract classes and methods… | by Ashfaque Khokhar | Medium
May 27, 2024 - Mammal has an additional abstract method walk(). The Dog class is a concrete subclass that attempts to extend both Mammal and Animal. Finally, there is a Main the class that creates an instance of Dog and calls its methods. However, the code provided for the Dog class is invalid in Java.
🌐
Tutorialspoint
tutorialspoint.com › java › java_abstraction.htm
Java - Abstraction
When you compile the above class, it gives you the following error − · Employee.java:46: Employee is abstract; cannot be instantiated Employee e = new Employee("George W.", "Houston, TX", 43); ^ 1 error · We can inherit the properties of Employee class just like concrete class in the following way −