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

 
 

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

Advertisement

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


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 22, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com