Start Coding Now

Abstract Classes in Java

Detailed guide on abstract classes. When to use abstract classes vs interfaces in Java.

Abstract Class

A class which is declared with the abstract keyword is known as an abstract class in Java. It can have abstract and non-abstract methods.

Rules:

  • Must be declared with abstract keyword.
  • Cannot be instantiated (cannot create objects).
  • Can have constructors and static methods.
  • Can have final methods.
  • abstract class Bike {
      abstract void run();
    }

    class Honda extends Bike { void run() { System.out.println("running safely"); } public static void main(String args[]) { Bike obj = new Honda(); obj.run(); } }

    Frequently Asked Questions