When superclass just defines the structure of the methods without providing complete implementation of every method and the subclass overrides the abstract methods in superclass and implements them, then the superclass is called as abstract class.
superclass specifies 'abstract' type before the methods who's structure is defined and implementation is not provided. We call these methods as abstract methods.
For example: - abstract methodname( );
The class that has at least one abstract method need to be specified as 'abstract' before the class name
abstract className
{
//Body of the class
}
Implementation for the abstract methods in the superclass will be provided in the sub classes which overrides the abstract methods of superclass.
Lets implement this on Eclipse IDE:
1. Create superclass 'Superclass' which contains abstract method whose structure is provided but implementation is not provided as shown below and save:
2. Create subclass 'Subclass' which overrides the abstract method in 'Superclass' and provides the implementation for the overridden method in subclass as shown below and save:
3. Create another class 'AbstractDemo' to create an object for calling the abstract methods implementation in subclass as shown below:
4. Save and Run the 'AbstractDemo' class file
5. Observe that the output is displayed in the console as shown below:
Download this project:
Click here to download the project containing the 'Superclass', 'Subclass' and 'AbstractDemo' class files used in this post (You can download the project and import into Eclipse IDE on your machine)
superclass specifies 'abstract' type before the methods who's structure is defined and implementation is not provided. We call these methods as abstract methods.
For example: - abstract methodname( );
The class that has at least one abstract method need to be specified as 'abstract' before the class name
abstract className
{
//Body of the class
}
Implementation for the abstract methods in the superclass will be provided in the sub classes which overrides the abstract methods of superclass.
Lets implement this on Eclipse IDE:
1. Create superclass 'Superclass' which contains abstract method whose structure is provided but implementation is not provided as shown below and save:
5. Observe that the output is displayed in the console as shown below:
Click here to download the project containing the 'Superclass', 'Subclass' and 'AbstractDemo' class files used in this post (You can download the project and import into Eclipse IDE on your machine)