13 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. If a class contain any abstract method then the class is declared as an abstract class. An abstract class is never instantiated. It is used to provide abstraction.

abstract class className {

 }

Before learning the abstract class, let's understand the abstraction in Java first.


13.1 | Abstraction

Abstraction is a process of hiding the implementation details and showing only functionality to the user. 

let's take an example, We send an email to others, where you type the mail body & receiver email id and send it, without knowing the internal processing of the email delivery.


13.2 | Abstract Method

A method, which is declared as abstract and does not have implementation is known as an abstract method. The method body will be defined by its subclass.

Example-

abstract return_type method_name ();  //no method body with abstract keyword


13.3 | Non-Abstract Method

A method, which is declared with a body and without abstract keyword is known as a non-abstract method. We also know the non-abstract method as a normal method and concrete method.


abstract return_type method_name () {
         
      ... 
       method body define here 
        ...

}


Example of the Abstract Class:

Abstract Class Example


The output of the above example