0

What is the real-time use of Abstract class?

Use of Abstract class real time source code.

7th Jun 2023, 5:37 PM
SHAIK GOUSEBASHA
2 Answers
+ 1
Abstract class is closely related to the OOP concept of inheritance. We are modeling a problem using objects. Some of these objects can be pretty similar, but they also have some different behavior. An abstract class is a common ancestor of multiple different classes. It is a concept, a model, a stereotype, and represents the commonalities of each subtype. One possible example is having an abstract Vehicle class, while you want to represent a Car, a Bicycle, a Boat and an Airplane as subclasses of Vehicle. The vehicle class may have a topSpeed and a capacity field, which is common for all subclasses. Maybe even a numberOfWheels field. And possibly virtual (abstract) methods to accelerate and to brake, but each subclass will implement this behavior differently. And some subclasses may have extra fields that are only relevant for them, not for the others. Maybe number of parachutes on board, is only interesting for an Airplane. https://code.sololearn.com/cf78kUN8wnaV/?ref=app
7th Jun 2023, 8:32 PM
Tibor Santa
Tibor Santa - avatar
0
Thanks
23rd Jun 2023, 6:38 PM
SHAIK GOUSEBASHA