-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypesOfInheritance.cpp
More file actions
48 lines (47 loc) · 880 Bytes
/
Copy pathtypesOfInheritance.cpp
File metadata and controls
48 lines (47 loc) · 880 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
//we have 5 different types of Inheritance.
/*
1)Single Inheritance
2)Multiple Inheritance
3)Hierarchical Inheritance
4)Multilevel Inheritance
5)Hybrid Inheritance (also known as Virtual Inheritance)
*/
//Single Inheritance.
#include<iostream>
using namespace std;
class Shape{
public:
void setValues(int l,int w,int h){
length=l;
width=w;
heigth=h;
}
protected:
int length;
int width;
int heigth;
};
class Rectangle:public Shape{
private:
void getArea(){
cout<<"Rectangle area:"<<length*width<<endl;
}
};
class Box:public Shape{
public:
void getVolume(){
cout<<"Box Volume:"<<length*width*heigth<<endl;
}
};
int main(){
Rectangle obj;
int l,w,h;
cout<<"Enter lenght,width and heigth:\n";
cin>>l>>w>>h;
obj.setValues(l,w,h);
obj.getArea();
Box obj1;
obj1.setValues(l,w,h);
obj1.getVolume();
return 0;
}