-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance.cpp
More file actions
57 lines (54 loc) · 988 Bytes
/
inheritance.cpp
File metadata and controls
57 lines (54 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//Program that shows concept of constructors, destructor and inheritance
#include<iostream>
#include<cstring>
using namespace std;
class mammal
{
protected:
int itsAge;
int itsWeight;
public:
mammal(int,int);
virtual ~mammal();
void getitsinfo();
};
mammal::mammal(int itsAge,int itsWeight)
{
cout<<"mammal constructor called"<<endl;
this->itsAge=itsAge;
this->itsWeight=itsWeight;
}
mammal::~mammal()
{
cout<<"mammal destructor called"<<endl;
}
void mammal::getitsinfo()
{
cout<<"Mammals age and weight"<<itsAge<<itsWeight<<endl;
}
class dog:private mammal
{
public:
dog(int,int);
~dog();
void setdata();
};
void dog::setdata()
{
// itsAge=0;
// itsWeight=0;
cout<<itsAge<<itsWeight;
}
dog::dog(int age,int w):mammal(age,w)
{
cout<<"Dog constructor called";
}
dog::~dog()
{
cout<<"Dog destructor called";
}
int main()
{
dog d(5,4);
d.setdata();
}