Abstract Class Method

Java Abstract Class and Methods with EXAMPLE

What is Abstract Class?

Abstract Classes are classes in Java, that declare one or more abstract methods.

Consider the following class hierarchy consisting of a Shape class which is inherited by three classes Rectangle, Circle, and Triangle. The Shape class is created to save on common attributes and methods shared by the three classes Rectangle, Circle, and Triangle. calculateArea() is one such method shared by all three child classes and present in Shape class.
 

Java Abstract Class and Methods

In this tutorial, you will learn-

Java Abstract Class and Methods

An object of the class triangle will give a triangle, again a common everyday shape.

Java Abstract Class and Methods

But what would an object of Class Shape look like in a practical world ??

Java Abstract Class and Methods

If you observe the Shape class serves in our goal of achieving inheritance and polymorphism. But it was not built to be instantiated.Such classes can be labeled Abstract. An abstract class can not be instantiated.

Syntax:

top
X
Glad to have you at Our Website
Welcome to WPBot
wpChatIcon