What is an abstract class?

What is an abstract class? Explain its purpose.

A class with one of 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 abstraction that is what to do, but not why to do.

For example, circle, square, triangle are the shapes in geometry. Each of these 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.
Java - Difference between an Abstract class and Interface
Difference between an Abstract class and Interface - An abstract class can have both abstract and concrete methods whereas an interface can have....
What is singleton class? Where is it used?
What is singleton class? Where is it used? - A class is defined as singleton class, if and only if it can create only one object. This class is useful when.....
Difference between a public and a non-public class
Difference between a public and a non-public class - A class with access specifier ‘public’ can be accessed across the packages. A package is like a folder in GUI....
Post your comment