Skip to content

Instantly share code, notes, and snippets.

@theoctober19th
Last active November 18, 2019 01:26
Show Gist options
  • Save theoctober19th/346e77d700934f0a0334263970562cda to your computer and use it in GitHub Desktop.
Save theoctober19th/346e77d700934f0a0334263970562cda to your computer and use it in GitHub Desktop.
/*
Create a class shape with a pure virtual member function display (). Derive two classes circle and rectangle. With member function by overriding member function in base class shape to display the name of respective shape. Write main function to create objects of derived classes and call display function.
*/
#import <iostream>
using namespace std;
class Shape{
public:
virtual void display() = 0;
};
class Circle: public Shape{
public:
void display(){
cout << "I am a circle" << endl;
}
};
class Rectangle: public Shape{
public:
void display(){
cout << "I am a Rectangle" << endl;
}
};
int main(){
Circle c;
Rectangle r;
c.display();
r.display();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment