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.
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
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();
}
}
Defining the definition of abstract method baseMethod1()
baseMethod2() method called form BaseAbstractClass
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.