Home Tutorial Java Core Abstract An Abstract class may or may not have abstract method.

 
 

An Abstract class may or may not have abstract method.
Posted on: March 22, 2010 at 12:00 AM
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

Related Tags for An Abstract class may or may not have abstract method.:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.