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







2 comments:

sheela rajesh said...

Thanks for sharing,this blog makes me to learn new thinks.
interesting to read and understand.keep updating it.
Selenium Training in Chennai
selenium training in anna nagar
JAVA Training in Chennai
Python Training in Chennai
Big data training in chennai
Android Training in Chennai
Selenium Training in Chennai
Selenium Course in Chennai

Aditi Ray said...

TreasureBox is operated by a group of young, passionate, and ambitious people that are working diligently towards the same goal - make your every dollar count, as we believe you deserve something better.
Check out the best
Mattress
entertainment unit
furniture nz