Sunday, 29 June 2014

What is Abstract Class in Java

Here are the points related Abstract class in Java that shall clear about Abstract word
  1. Abstract class is the one of class that cannot be instantiated.
  2. If you want to get implementation of any method from child class(other person) then abstract method can use in this sense.
  3. Abstract class are incomplete ,subclass must declare missing piece to become concrete class(Class whose object can be instantiated ) , otherwise these subclass also become abstract class.
  4. You can achieve abstraction that is main pillar of OOP through by "abstract classes".
  5. Abstraction hide the irrelevant detail of an object.
  6. Abstract use for IS A Relationship (Inheritance).
  7. Abstraction use for to achieve Polymorphic behavior (Another main pillar of OOP)   
Here is example of abstract class
   abstract public Employee{

         abstract public void earning();// abstract method

         public void showAge(){//concrete method
                System.out.println("My Age ??");
          }
   }

   8. abstract class should not be private and not contained private method.
   9.  You extends single abstract class not multiple because Java is Single supported Inheritance
   10.  Abstract class must contain  1 or more than 1 abstract method
   11.  If any class contain abstract method then it should explicitly declare abstract class even if it contain 
        concrete method.
   12. Constructor and static method cannot be declared as abstract because constructor are not inherited.

   public class HourlyEmployee extends Employee{
             
        public void earning(){// Implementation of  Abstract Method
                System.out.println("My Earning ");
        }

      @Override
      public void showAge(){
                System.out.println("My Age ??");
      }
   }//end of class

   13. If child class have not implement the abstract method of super class then it become also abstract class.
   14. Attempting to instantiate the object of abstract class is an Compilation error.
   15. Abstract super class variable can hold the reference of child concrete object.


     Employee e=new HourlyEmployee();

No comments:

Post a Comment