0% found this document useful (0 votes)
2 views2 pages

Abstract Class in OOP

An abstract class in C++ cannot be instantiated and serves as a base class with a common interface for derived classes. It must contain at least one pure virtual function, which derived classes must override to become concrete. For example, the Shape class is abstract with a pure virtual function draw(), while Circle and Square are derived classes that implement this function.

Uploaded by

Aksjsy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Abstract Class in OOP

An abstract class in C++ cannot be instantiated and serves as a base class with a common interface for derived classes. It must contain at least one pure virtual function, which derived classes must override to become concrete. For example, the Shape class is abstract with a pure virtual function draw(), while Circle and Square are derived classes that implement this function.

Uploaded by

Aksjsy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Abstract Class:

An abstract class is a class that cannot be instan-ated, and is typically used as a base
class. It provides a common interface for derived classes. In C++, an abstract class
contains at least one pure virtual func-on.

Key Points about Abstract Class in C++

• Contains at least one pure virtual function.


• Cannot create an object of an abstract class.
• Used to define an interface that derived classes must implement.
• Derived classes must override all pure virtual functions to become concrete (non-
abstract).

Example:
Explanation

• Shape is an abstract class with a pure virtual function draw().


• Circle and Square inherit from Shape and provide their own implementation
of draw().
• We cannot create an object of Shape, but we can use a pointer of type Shape* to point
to derived class objects and call overridden functions (polymorphism).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy