Interview Questions, Answers and Tutorials

13 Abstract class

13 Abstract class

A class that 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 contains 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

2 thoughts on “13 Abstract class

Comments are closed.