Any class that contains one or more abstract method must also be declared abstract.
We can declare an abstract class by using the abstract keyword in front of class keyword at the beginning of the class declaration.
An abstract method is a method which declares in super class and defines by the associate subclass.
To declare abstract method we a place abstract method
Syntax
abstract type name(parameter list);
- Abstract class contains associate is a class in which we can declare an abstract method but can’t define.
- An abstract class must have at least one method of
the abstract type. - An abstract class can’t have
any object. - Abstract class can’t be directly instantiated with the new operator.
- We can’t declare
abstract constructor or abstract static method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | abstract class A { // Class A is a Abstract class abstract void display();// declare abstract method display() void show() { System.out.println(" Abstract Class show() "); } } class B extends A { void display() { // definition of abstract method System.out.println("abstract method definition"); } } public class Test { public static void main(String arg[]) { B objB = new B(); objB.show(); objB.display(); } } |
1 2 | Abstract Class show() abstract method definition |