The abstract modifier, for creating abstract classes and methods

The abstract modifier, for creating abstract classes and methods

Previous Home Next

 

Abstract Class:
An abstract class can never be instantiated.
If a class is declared as abstract then the main purpose is for the class to be extended.

 Abstract Methods:

An abstract method is a method declared with out any implementation.

Any class that extends an abstract class must implement all the abstract methods of the super class unless the 
subclass is also an abstract class.

If a class contains one or more abstract methods then the class need to  be declared abstract.
An abstract class does not need to contain abstract methods.

Note: An abstract method need to be end with semicolon(;)
 


 
 public abstract class SuperClass
{
abstract void method(); //abstract method
}

class SubClass extends SuperClass
{

void method() // implements the abstract method
{

.........
}

Previous Home Next