Purpose of Abstract Class in Java
Abstract Class:
It indicates that a method must always be redefined in a subclass, this is done by using the abstract keyword in the method definition.
Purpose of Abstract Class:
1. We can’t use abstract classes to instantiate objects directly.
2. The abstract methods of an abstract class must be defined in its subclass.
3. We can’t declare abstract constructors or abstract static methods.
Syntax:
abstract class test { ............. ............. abstract void add(); ............. ............. }
Program:
abstract class Test { abstract void display(); } class Temp extends Test { void display() { System.out.println("Hello Java!"); } public static void main(String[] args) { Temp t1 = new Temp(); t1.display(); } }
Output:
Hello Java!