August 03, 2011

Abstract in Java

  • An abstract class or method can be declared by using the keyword abstract.
  • Example
                   abstract class AbstractClassname{   }
                   abstract returntype methodname();
  •  All methods inside the abstract class should be declared abstract.Otherwise, the method definition should be provided for the particular method in the abstract class itself.
  • Abstract class can be extended to any class by using the keyword extends.
  • Example
                  class classname extends AbstractClassname{    }
  • Abstract class is mearly like a ordinary class except that we cann't be able to create objects from it.
  • When an abstract class is subclassed, the subclass should provide implementations for all of the abstract methods in its parent class. However, if it does not, the subclass must also be declared abstract.
  • We can create constructors for the abstract classes.

No comments:

Post a Comment

Connecting Java program to Database

It is very simple to establish a connection to the Database from a Java program          Class.forName("com.mysql.jdbc.Driver...