Difference between Abstract Class and Concrete Class in Java

Abstract Class: An abstract class is a type of class in Java that is declared by the abstract keyword. An abstract class cannot be instantiated directly, i.e. object of such class cannot be created directly using new keyword. An abstract class can be instantiated either by concrete subclass, or by defining all the abstract method along with the new statement. It may or may not contain abstract method. An abstract method is declared by abstract keyword, such methods cannot have a body. If a class contains abstract method, then it also needs to be abstract.

Concrete Class: A concrete class in Java is a type of subclass, which implements all the abstract method of its super abstract class which it extends to. It also has implementations of all methods of interfaces it implements.

Abstract Class vs Concrete Class

  1. Modifier: An abstract class is declared using abstract modifier. Concrete class should not be declared using abstract keyword, on doing so, it will also become abstract class.

  2. Instantiation: An abstract class cannot be instantiated directly, i.e. object of such class cannot be created directly using new keyword. An abstract class can be instantiated either by concrete subclass, or by defining all the abstract method along with the new statement. A concrete class can be instantiated directly, using a new keyword.

    Example: Invalid direct instantiation of an abstract class.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    abstract class DemoAbstractClass {
        abstract void display();
    }
      
    public class JavaApplication {
        public static void main(String[] args)
        {
            DemoAbstractClass AC = new DemoAbstractClass();
            System.out.println("Hello");
        }
    }

    chevron_right

    
    

    Compile Error:

    prog.java:9: error: DemoAbstractClass is abstract; cannot be instantiated
            DemoAbstractClass AC = new DemoAbstractClass();
                                   ^
    

    Example: Valid instantiation by defining all abstract method of an abstract class.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    abstract class DemoAbstractClass {
        abstract void display();
    }
      
    public class JavaApplication {
        public static void main(String[] args)
        {
            DemoAbstractClass AC = new DemoAbstractClass() {
                void display()
                {
                    System.out.println("Hi.");
                }
            };
            AC.display();
            System.out.println("How are you?");
        }
    }

    chevron_right

    
    

    Output:

    Hi.
    How are you?
    

    Example: Direct instantiation of concrete using new keyword.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    abstract class DemoAbstractClass {
        abstract void display();
    }
      
    class ConcreteClass extends DemoAbstractClass {
        void display()
        {
            System.out.println("Hi.");
        }
    }
      
    public class JavaApplication {
        public static void main(String[] args)
        {
            ConcreteClass C = new ConcreteClass();
            C.display();
            System.out.println("How are you?");
        }
    }

    chevron_right

    
    

    Output:

    Hi.
    How are you?
    
  3. Abstract methods: An abstract class may or may not, have an abstract method. A concrete class cannot have an abstract method, because class containing an abstract method must also be abstract.
  4. Final: An abstract class cannot be final, because all its abstract methods must defined in the subclass. A concrete class can be declared as final.
  5. Interface: Interface implementation is not possible with abstract class, however, it is possible with concrete class.

Abstract Class Concrete Class
An abstract class is declared using abstract modifier. A concrete class is note declared using abstract modifier.
An abstract class cannot be directly instantiated using the new keyword. A concrete class can be directly instantiated using the new keyword.
An abstract class may or may not contain abstract methods. A concrete class cannot contain an abstract method.
An abstract class cannot be declared as final. A concrete class can be declared as final.
Interface implementation is not possible Interface implementation is possible.

Some important points:

  • A concrete class is a subclass of an abstract class, which implements all its abstract method.
  • Abstract methods cannot have body.
  • Abstract class can have static fields and static method, like other classes.
  • An abstract class cannot be declared as final.
  • Only abstract class can have abstract methods.
  • A private, final, static method cannot be abstract, as it cannot be overridden in a subclass.
  • Abstract class cannot have abstract constructors.
  • Abstract class cannot have abstract static methods.
  • If a class extends an abstract class, then it should define all the abstract methods (override) of the base abstract class. If not, the subclass(the class extending abstract class) must also be defined as abstract class.


My Personal Notes arrow_drop_up