Wednesday, December 14, 2016

Abstract Class in Java

Abstraction :

      Abstraction is the process of hiding the internal operations from the user and it just shows only the functionality. The user can get results without knowing the internal processing. It is not fully abstractions like Interface in Java.
For ex : If you're sending email to anyone, do you know how it is sent to receiver ? do you know the internal operations ? Just you're adding only the recipient email address,subject and body of the content that's all but you don't what is happening internally. So the abstraction is the process of hiding the internal details and it shows only the results to the end user.


Abstract Class :

     Abstract class is the class which is declared as abstract keyword. The abstract class can't be instantiated. To use abstract class, the class needs to be inherited by subclass and its all abstract methods should be implemented. It can have methods with body(concrete methods) and without body(abstract method) also. It can have constructors, data members and methods without body also.

Abstract Method :

      In abstract class, the methods without body are called abstract method and it's declared with abstract keyword. It can't be final & static. The abstract methods are implemented by subclass. If any class has abstract methods, then the class needs to be defined as abstract.

 Example :
 abstract class DevelopersA{ 

      System.out.println("Java developer");


   abstract void pythonist(); //abstract methods

   public void developerDesignation(){

       System.out.println("Android and iOS developer ");

 class DevelopersB extends DevelopersA{  
     public void pythonist(){    //abstract method implementations

       System.out.println("I am a python developer");


 class Manager{  

 public static void main(String args[]){  

  DevelopersA obj = new DevelopersB();


Output :

Java developer
I am a python developer
Android and iOS developer 

Abstract classes are used by any sub classes and they can perform different operations ie providing different implementations for abstract methods. That's all.

Happy Coding... :)
Location:India, Tamil Nadu, Tuticorin Thoothukudi, Tamil Nadu, India