Abstract class in Object Oriented Programming

When a class contains at least one pure virtual function, Then it is known as an abstract class. An abstract class is something which is to be hidden by people and on which modifications can be done in future. Since an abstract class contains at least one function for which no body exists, technically it can be considered as incomplete and therefore no object is created. Thus we can also define an abstract class as a class for which no object is created. We may conclude that an abstract class exists only to be inherited. We may still create pointer to an abstract class. In the following example, class area is an abstract class because it has a pure virtual function get_area().




Example of Abstract Class in OOP's:
#include<iostream>
using namespace std;
class area
{
double x, y;
public:
void set_area(int d1, int d2)
{
x = d1;
y = d2;
}
void get_dim(double  &d1, double  &d2)
{
d1 = x;
d2 = y;

}
virtual double get_area()=0;
};


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: