An Abstract class may or may not have abstract method.


 

An Abstract class may or may not have abstract method.

In this tutorial you will com to know how abstract class is used. Abstract Class do not instantiate.

In this tutorial you will com to know how abstract class is used. Abstract Class do not instantiate.

Description:

An Abstract is also known as Abstract Base Class. Abstract Class do not instantiate it means no object is made of this class. Its method declaration is done in its derived class not in the abstract class. Abstract itself means incomplete so through inheritance it method method is defined.

Program Description:

In this example you are going to see that there is abstract class and a class derived class which extends the abstract class. In the BaseAbstractClass class there is a abstract method which is having no defination. It is defined under the DerivedClass class.  This all defined the working behavior of abstract class

Code:

abstract class BaseAbstractClass {

abstract void baseMethod1();

// defination done in DerivedClass class

void baseMethod2() {

System.out.println("baseMethod2() method called form BaseAbstractClass");

}

}

class DerivedClass extends BaseAbstractClass {

void baseMethod1() {

System.out.println(" Defining the definition of abstract method baseMethod1()");

}

}

class Prog22 {

public static void main(String[] args) {

DerivedClass b = new DerivedClass();

b.baseMethod1();

b.baseMethod2();

}

}

Output:

Defining the definition of abstract method baseMethod1()
baseMethod2() method called form BaseAbstractClass

Ads