0% found this document useful (0 votes)
48 views1 page

Constructor and Destructor Calling

The document defines several classes - D, E, A, B, C - that inherit from each other to demonstrate object oriented programming concepts in C++. Class A inherits publicly from classes D and E. Class B inherits publicly from class A, overriding the doSomething() method. Class C inherits virtually publicly from class B. The main function dynamically creates objects of types B and C, calls doSomething() on pointers to the base class A to show polymorphic behavior depending on the actual object type.

Uploaded by

Saif khawaja
Copyright
© Attribution Non-Commercial (BY-NC)
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)
48 views1 page

Constructor and Destructor Calling

The document defines several classes - D, E, A, B, C - that inherit from each other to demonstrate object oriented programming concepts in C++. Class A inherits publicly from classes D and E. Class B inherits publicly from class A, overriding the doSomething() method. Class C inherits virtually publicly from class B. The main function dynamically creates objects of types B and C, calls doSomething() on pointers to the base class A to show polymorphic behavior depending on the actual object type.

Uploaded by

Saif khawaja
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 1

Name:_______________________

Reg No:__________________________

Object Oriented Programming


# include <iostream> # include <string> using namespace std; class D { public: D(){cout<<"D Constructor Called"<<endl;} void doSomething() {cout<<"D class method called"<<endl;} ~D(){cout<<"D Destructor Called"<<endl;} }; class E { public: E(){cout<<"E Constructor Called"<<endl;} void doSomething() {cout<<"E class method called"<<endl;} ~E(){cout<<"E Destructor Called"<<endl;} }; class A:public D, public E { public: A(){cout<<"A Constructor Called"<<endl;} void doSomething() {cout<<"A class method called"<<endl;} ~A(){cout<<"A Destructor Called"<<endl;} }; class B:public A { public: B(){cout<<"B Constructor Called"<<endl;} virtual void doSomething() {cout<<"B class method called"<<endl;} ~B(){cout<<"B Destructor Called"<<endl;} }; class C:virtual public B { public: C(){cout<<"C Constructor Called"<<endl;} void doSomething() {cout<<"C class method called"<<endl;} ~C(){cout<<"C Destructor Called"<<endl;} }; int main () { A * b=new B; B * d=new C; A * bptr=b; bptr->doSomething(); bptr=d; bptr->doSomething(); delete b; delete d; delete bptr; return 0; }

You might also like