Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
36 views

Inheritance Problems

The document defines three C++ classes - base, derived, and subderived - where derived inherits from base and subderived inherits from derived. Each class defines multiple constructors that print messages. The main function creates objects of subderived with different constructors, demonstrating inheritance and constructor calling between the classes.

Uploaded by

Devendra Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Inheritance Problems

The document defines three C++ classes - base, derived, and subderived - where derived inherits from base and subderived inherits from derived. Each class defines multiple constructors that print messages. The main function creates objects of subderived with different constructors, demonstrating inheritance and constructor calling between the classes.

Uploaded by

Devendra Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

#include<iostream>

using namespace std;

class base

public:

base()

cout<<"Base class defalut constructor \n";

base(int x)

cout<<"BASE One argument constructor"<<endl;

base(int x,int y)

cout<<"BASE Two argument constructor \n";

};

class derived:public base

public:

derived()

cout<<"DERIVED default class constructor \n";

derived(int x)

cout<<"DERIVED class one constructor \n";


}

derived(int x,int y)

cout<<"DERIVED default two constructor \n";

};

int main()

derived a;

derived b(2);

derived c(2,3);

return 0;

#include<iostream>

using namespace std;

class base

public:

base()

{
cout<<"Base class defalut constructor \n";

base(int x)

cout<<"BASE One argument constructor"<<endl;

base(int x,int y)

cout<<"BASE Two argument constructor \n";

};

class derived:public base

public:

int a;

derived():base(a)

cout<<"DERIVED default class constructor \n";

derived(int x)

cout<<"DERIVED class one constructor \n";

derived(int x,int y)

cout<<"DERIVED default two constructor \n";

}
};

int main()

derived a;

derived b(2);

derived c(2,3);

return 0;

#include<iostream>

using namespace std;

class message

int x;

public:

message()

cout<<"NULL MESSAGE \n";

message(int a)

cout<<"Integer message \n";


}

message(const message& m)

cout<<"Copy message \n";

void send(message m1)

cout<<"Send message \n";

message receive(message &t)

message temp(10);

cout<<"Recieve message \n";

return t;

~message()

cout<<"Destructor is called \n";

};

int main()

message t1;

message t2=t1;

message t3;

t3=t2;

t1.send(t2);

t2=t1.receive(t3);

return 0;
}

#include<iostream>

using namespace std;

class base

public:

base()

cout<<"Base class defalut constructor \n";

base(int x)
{

cout<<"BASE One argument constructor"<<endl;

base(int x,int y)

cout<<"BASE Two argument constructor \n";

};

class derived:public base

public:

int a;

derived()

{
cout<<"DERIVED default class constructor \n";

derived(int x)

cout<<"DERIVED class one constructor \n";

derived(int x,int y)

cout<<"DERIVED default two constructor \n";

};

class subderived:public derived

public:

subderived()

{
cout<<"SUBDERIVED default constructor \n";

subderived(int x)

cout<<"SUBDERIVED one argument constructor \n";

subderived(int x,int y)

cout<<"SUBDERIVED two argrument constructor \n";

};

int main()

subderived a;

subderived b(2);

subderived c(2,3);

return 0;

}
#include<iostream>

using namespace std;

class base

public:

base()

cout<<"Base class defalut constructor \n";

base(int x)

{
cout<<"BASE One argument constructor"<<endl;

base(int x,int y)

cout<<"BASE Two argument constructor \n";

};

class derived:public base

public:

int a;

derived():base(a)

cout<<"DERIVED default class constructor \n";


}

derived(int x)

cout<<"DERIVED class one constructor \n";

derived(int x,int y)

cout<<"DERIVED default two constructor \n";

};

class subderived:public derived

public:

subderived()

cout<<"SUBDERIVED default constructor \n";

}
subderived(int x)

cout<<"SUBDERIVED one argument constructor \n";

subderived(int x,int y)

cout<<"SUBDERIVED two argrument constructor \n";

};

int main()

subderived a;

subderived b(2);

subderived c(2,3);

return 0;

You might also like