Table of Contents
In this tutorial, we will discuss the Oop concept of Abstract class in C++ language
An abstract class in C++ language, which is a class contain pure one or more(at least one) virtual function in a base class . A pure virtual function is a virtual member function, that noticeable as having no any implementation.
virtual void functionName()=0;
virtual void sayHollow()=0;
Some important points about abstract class
class class_Name { public: //A pure virtual function is specified by placing "= 0" in its declaration as follows virtual display()=0; //pure virtual function //it has no definition }
Example given below
Example 1
class shape{//class ahape has a vertual function virtual void draw()=0; //virtual function with no implementation } class circle{ //derived (1) class circle void draw(){ // implementation of draw() function } class rectangle{ //derived (2) class rectangle void draw(){ // implementation of draw() function } class square{ //derived (2) class squair void draw(){ // implementation of draw() function }
At the above example, shape is a base class. Draw() is a virtual function is inside the shape( base) class which has no implementation, but it is only definition. So class shape is a abstract class. function draw() is a pure virtual function.
Every derived class having implementation of draw() method
facts
A class is abstract if it has at least one pure virtual function
Program 1
When the above code is executed, It produces the following result
this is teacher class this is principal class this is school clark class End the program
Program 2
When the above code is executed, It produces the following result
This is first derived class This is second derived class End the program
Related Links
Encapsulation in C++ Encapsulation in Java
Polymorphism in C++ Methodoverriding in Java
Method overloading in java Constructor overloading in Java
Exception Handling in Java Abstract class in Java
Method over riding in Python
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.