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
🌐
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.
🌐
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).
🌐
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.
🌐
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.
🌐
Javatpoint
javatpoint.com › abstract-class-in-java
Abstract class in Java - Javatpoint
Abstract class in Java - Abstract class in java with abstract methods and examples. An abstract class can have abstract and non-abstract (concrete) methods and can't be instantiated with inheritance, polymorphism, abstraction, encapsulation, exception handling, multithreading, IO Streams, Networking, String, Regex, Collection, JDBC etc.
Find elsewhere
🌐
BeginnersBook
beginnersbook.com › 2013 › 05 › java-abstract-class-method
Abstract Class in Java with example
It’s vice versa is not always true: If a class is not having any abstract method then also it can be marked as abstract. It can have non-abstract method (concrete) as well. I have covered the rules and examples of abstract methods in a separate tutorial, You can find the guide here: Abstract method in Java ...
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
}
}
🌐
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 −
🌐
Jenkov
jenkov.com › tutorials › java › abstract-classes.html
Java Abstract Classes
This Java abstract class tutorial ... in Java in more detail towards the end of this text. In Java you declare that a class is abstract by adding the abstract keyword to the class declaration. Here is a Java abstract class example:...
🌐
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.
🌐
ScholarHat
scholarhat.com › home
What is Abstraction in Java with Examples & Its Uses
In the Main class, Dog and Cat instances are created, and their respective methods are called. Animals cannot be instantiated directly; however, their subclasses can be utilized to generate objects. Woof Zzz... Meow Zzz... Interfaces are another way of implementing abstraction in Java.
Published   September 5, 2025
🌐
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.
Top answer
1 of 15
355

An abstract class is a class which cannot be instantiated. An abstract class is used by creating an inheriting subclass that can be instantiated. An abstract class does a few things for the inheriting subclass:

  1. Define methods which can be used by the inheriting subclass.
  2. Define abstract methods which the inheriting subclass must implement.
  3. Provide a common interface which allows the subclass to be interchanged with all other subclasses.

Here's an example:

abstract public class AbstractClass
{
    abstract public void abstractMethod();
    public void implementedMethod() { System.out.print("implementedMethod()"); }
    final public void finalMethod() { System.out.print("finalMethod()"); }
}

Notice that "abstractMethod()" doesn't have any method body. Because of this, you can't do the following:

public class ImplementingClass extends AbstractClass
{
    // ERROR!
}

There's no method that implements abstractMethod()! So there's no way for the JVM to know what it's supposed to do when it gets something like new ImplementingClass().abstractMethod().

Here's a correct ImplementingClass.

public class ImplementingClass extends AbstractClass
{
    public void abstractMethod() { System.out.print("abstractMethod()"); }
}

Notice that you don't have to define implementedMethod() or finalMethod(). They were already defined by AbstractClass.

Here's another correct ImplementingClass.

public class ImplementingClass extends AbstractClass
{
    public void abstractMethod() { System.out.print("abstractMethod()"); }
    public void implementedMethod() { System.out.print("Overridden!"); }
}

In this case, you have overridden implementedMethod().

However, because of the final keyword, the following is not possible.

public class ImplementingClass extends AbstractClass
{
    public void abstractMethod() { System.out.print("abstractMethod()"); }
    public void implementedMethod() { System.out.print("Overridden!"); }
    public void finalMethod() { System.out.print("ERROR!"); }
}

You can't do this because the implementation of finalMethod() in AbstractClass is marked as the final implementation of finalMethod(): no other implementations will be allowed, ever.

Now you can also implement an abstract class twice:

public class ImplementingClass extends AbstractClass
{
    public void abstractMethod() { System.out.print("abstractMethod()"); }
    public void implementedMethod() { System.out.print("Overridden!"); }
}

// In a separate file.
public class SecondImplementingClass extends AbstractClass
{
    public void abstractMethod() { System.out.print("second abstractMethod()"); }
}

Now somewhere you could write another method.

public tryItOut()
{
    ImplementingClass a = new ImplementingClass();
    AbstractClass b = new ImplementingClass();

    a.abstractMethod();    // prints "abstractMethod()"
    a.implementedMethod(); // prints "Overridden!"     <-- same
    a.finalMethod();       // prints "finalMethod()"

    b.abstractMethod();    // prints "abstractMethod()"
    b.implementedMethod(); // prints "Overridden!"     <-- same
    b.finalMethod();       // prints "finalMethod()"

    SecondImplementingClass c = new SecondImplementingClass();
    AbstractClass d = new SecondImplementingClass();

    c.abstractMethod();    // prints "second abstractMethod()"
    c.implementedMethod(); // prints "implementedMethod()"
    c.finalMethod();       // prints "finalMethod()"

    d.abstractMethod();    // prints "second abstractMethod()"
    d.implementedMethod(); // prints "implementedMethod()"
    d.finalMethod();       // prints "finalMethod()"
}

Notice that even though we declared b an AbstractClass type, it displays "Overriden!". This is because the object we instantiated was actually an ImplementingClass, whose implementedMethod() is of course overridden. (You may have seen this referred to as polymorphism.)

If we wish to access a member specific to a particular subclass, we must cast down to that subclass first:

// Say ImplementingClass also contains uniqueMethod()
// To access it, we use a cast to tell the runtime which type the object is
AbstractClass b = new ImplementingClass();
((ImplementingClass)b).uniqueMethod();

Lastly, you cannot do the following:

public class ImplementingClass extends AbstractClass, SomeOtherAbstractClass
{
    ... // implementation
}

Only one class can be extended at a time. If you need to extend multiple classes, they have to be interfaces. You can do this:

public class ImplementingClass extends AbstractClass implements InterfaceA, InterfaceB
{
    ... // implementation
}

Here's an example interface:

interface InterfaceA
{
    void interfaceMethod();
}

This is basically the same as:

abstract public class InterfaceA
{
    abstract public void interfaceMethod();
}

The only difference is that the second way doesn't let the compiler know that it's actually an interface. This can be useful if you want people to only implement your interface and no others. However, as a general beginner rule of thumb, if your abstract class only has abstract methods, you should probably make it an interface.

The following is illegal:

interface InterfaceB
{
    void interfaceMethod() { System.out.print("ERROR!"); }
}

You cannot implement methods in an interface. This means that if you implement two different interfaces, the different methods in those interfaces can't collide. Since all the methods in an interface are abstract, you have to implement the method, and since your method is the only implementation in the inheritance tree, the compiler knows that it has to use your method.

2 of 15
79

A Java class becomes abstract under the following conditions:

1. At least one of the methods is marked as abstract:

public abstract void myMethod()

In that case the compiler forces you to mark the whole class as abstract.

2. The class is marked as abstract:

abstract class MyClass

As already said: If you have an abstract method the compiler forces you to mark the whole class as abstract. But even if you don't have any abstract method you can still mark the class as abstract.

Common use:

A common use of abstract classes is to provide an outline of a class similar like an interface does. But unlike an interface it can already provide functionality, i.e. some parts of the class are implemented and some parts are just outlined with a method declaration. ("abstract")

An abstract class cannot be instantiated, but you can create a concrete class based on an abstract class, which then can be instantiated. To do so you have to inherit from the abstract class and override the abstract methods, i.e. implement them.

🌐
GeeksforGeeks
geeksforgeeks.org › java › abstraction-in-java-2
Abstraction in Java - GeeksforGeeks
By abstracting functionality, changes in the implementation do not affect the code that depends on the abstraction. Java provides two ways to implement abstraction, which are listed below: ... The television remote control is the best example ...
Published   November 14, 2017
🌐
Simplilearn
simplilearn.com › home › resources › software development › java tutorial for beginners › what is an abstract class in java and how to implement it?
What is an Abstract Class in Java and How to Implement It?
January 26, 2025 - This article explains what is abstract class in java, features of abstract class, the syntax and examples of abstract class, and the interface vs abstract class. So, read on to learn more!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
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.