Saturday, May 21, 2011

Abstract class in Java

Abstract class is class which has more than one abstract method which doesn’t have method body but at least one of its methods need to be implemented  in derived Class.  
Abstract classes can be used to implement the inheritance relationship between the classes that belongs same hierarchy.
  1. Classes and methods can be declared as abstract.
  2. Abstract class can extend only one Class.
  3. If a Class is declared as abstract , no instance of that class can be created.
  4. If a method is declared as abstract, the sub class gives the implementation of that class.
  5. Even if a single method is declared as abstract in a Class ,  the class itself  can be declared as abstract.
  6. Abstract class have at least one abstract  method and others may be concrete.
  7. In abstract Class the keyword abstract must be used for method.
  8. Abstract classes have sub classes.
  9. Combination of modifiers Final and Abstract is illegal in java.
The general form of abstract class is :     
    abstract type name (parameter list);

The Number class in the java.lang package represents the abstract concept of numbers. It makes sense to model numbers in a program, but it doesn't make sense to create a generic number object.

Sample Abstract Classes: HttpServlet, GenericServlet 

You can more avout Interface here 
Click here for Difference between Abstract class and Iterface

No comments: