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
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.