What is an abstract class in Java ?

Article by: Manish Methani

Last Updated: October 27, 2021 at 8:04am IST
3 min 22 sec read

Abstract class in Java is that class that contains abstract methods as well as concrete methods. Abstract methods are the methods with no body and concrete methods are the methods which contain the body. Clear?

Before understanding more about abstract methods and abstract class first we will clear why to use abstract methods?

Abstract Methods

Assume that you have to write the displayMenu() method for applications like Notepad++, Paint. Now we know that Notepad++ has different menu buttons like Font-size, paragraph, etc. whereas Paint contains different displayMenu.

Then in this case we write declare an abstract method in the parent class that has nobody. Notepad++ will implement its functionality and Paint will implement its functionality.

//Abstract class
abstract class Display{
   /* This is an abstract method, the child class
    * must implement these methods
   public abstract void displayMenu();

   //Regular method 
   public void concreteDisplayMethod(){
	System.out.println("Concrete Display Method");

class Notepad extends Display
    public void displayMenu(){
     	System.out.println("Notepad++ Display Menu");

class Paint extends Display
    public void displayMenu(){
     	System.out.println("Paint Display Menu");

//Regular class extends abstract class
class JavaClassDemo{

   public static void main(String args[]){
   //Notepad Object
    Notepad obj = new Notepad();

    //Paint Object
    Paint objPaint = new Paint();


Notepad++ Display Menu
Concrete Display Method
Paint Display Menu
Concrete Display Method

If you try to instantiate an object of abstract class then you will get this compilation error

Main.java:36: error: Display is abstract; cannot be instantiated
	Display obj = new Display();
1 error

Rules to use Abstract class

1) Abstract class cannot be instantiated. An abstract class can contain both abstract methods as well as concrete methods.

2) But concrete methods cannot contain abstract methods.

3) If a class contains an abstract method then that class must be an abstract class.

4) If the class extends the Abstract class then that subclass must implement the abstract method else that class will also become an abstract class.

5) If a class contains an abstract method then the class must be declared as an abstract class otherwise you should get a compilation error. Illegal case,

public class IllegalClass
    public abstract void doIt();

Here the method is declared as abstract but class is not declared as abstract. That's why the compilation error has occurred. To resolve this issue you have to declare a class as abstract also.

You declared the method as abstract but the class is not abstract that's why you see a compilation error.

Legal Case:-

public abstract class LegalClass{

     void goodMethod() {
        // lots of real implementation code here

If a class is abstract with no methods then it works.

Learn Flutter, FlutterFlow,
Firebase & Angular.

Looking to learn how to create the production-ready apps
from scratch? Well, you are at the right place.

₹1299 or $15.56

Learn to create the Dating App using No-Code Tool FlutterFlow

Level: Advanced

Explore Curriculum
₹1299 or $15.56

Flutter Mobile App Development Course

Explore Curriculum
₹1299 or $15.56

The Complete Angular Course

Explore Curriculum
₹1299 or $15.56

Dart Programming for Absolute Beginners

Coming Soon

Next.js course

Start Watching

Fundamentals of Computer Programming Languages

Start Watching

Learn HTML, CSS & Bootstrap

Start Watching

Latest Web Stories


Learn how to open WhatsApp using FlutterFlow | Step by Step Guide

Test your skills with these expert-led curated
Mock Tests.

C Programming Test

Test your C Programming skills with this comprehensive mock test on C Programming.

Take Test

Flutter Test

Solve most asked Interview Questions on Flutter and Test your foundational skills in flutter.

Take Test

GATE(CSE) Operating Systems

Solve most asked GATE Questions in Operating Systems and test your Gate Score.

Take Test


This is a mock test designed to help you assess your knowledge and skills in HTML and CSS.

Take Test

(GATE CSE) Data Structures & Algorithms Test

Solve most asked GATE Questions in Data Structures and Algorithms and test your Gate Score.

Take Test

Download the Codzify
Mobile App

Learn Anytime, Anywhere at your own pace. Scan the QR Code with your Mobile Camera to Download the Codzify Mobile App.

Codzify Mobile App Codzify Mobile App
Codzify Logo

Terms and Conditions    Cookie Policy   Refund Policy   Adsense Disclaimer