Abstract Class in Java Programming

Abstract Class in Java Programming

Previous Home Next

 

Java Abstract classes are used to declare common characteristics of subclasses.
 An abstract class cannot be instantiated.

It can only be used as a superclass for other classes that extend the abstract class. 
Abstract classes are declared with the abstract keyword.
Abstract classes are used to provide a template or design for concrete subclasses down the inheritance tree.
 

 As mentioned, it is not possible to instantiate an abstract class.Therefore no objects of class A are declared in the program.

 
   abstract class A 
{
abstract void callme();
// concrete methods are still allowed in abstract classes
void callmetoo()
{
System.out.println("This is a concrete method.");
}
}

class B extends A
{
void callme()
{
System.out.println("B is implementation of callme.");
}
}

class AbstractDemo
{
public static void main(String args[]) {
B b = new B();
b.callme();
b.callmetoo();
}
}


Previous Home Next