Define an abstract class. Explain its purpose

Define an abstract class. Explain its purpose.

A class with one or more abstract methods is called an Abstract class. An abstract method is a method with signature with out code in it.

The purpose of an abstract class is to implement the concept of abstraction that is what to do, but not why to do.

For example, circle, square, triangle are the shapes in geometry. Each of these are shapes, whose super class is Shape. Each of them have perimeter and area which cannot be defined in the super class, say Shape. And without Shape none of these exist.

In the above scenario, a method, say calculateArea() can not be defined in the super class Shape though every ‘Shape’ have area. The solution is to declare the Shape as an abstract class which has calculateArea () as an abstract method.

The concrete implementation of the calculateArea () method is to be implemented in the Circle, Square and Triangle classes which are sub classes to the abstract class Shape.
What is the difference between an Abstract class and Interface?
Abstract class and Interface - An abstract class can have both abstract and concrete methods whereas an interface can have only method signatures...
What is singleton class? Where is it used?
What is singleton class? - A class is defined as singleton class, if and only if it can create only one object...
What is a native method?
What is a native method? - A native method is a method which is implemented in a non-java language that is targeted for a single machine type...
Post your comment