-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest4.cpp
More file actions
42 lines (37 loc) · 880 Bytes
/
test4.cpp
File metadata and controls
42 lines (37 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
#include <iostream>
using namespace std;
// It prevents name conflicts in different packages (::) This is known as scope resolution operator
namespace first {
int x = 2;
};
namespace second {
int x = 7;
};
class Box{
public:
int length;
int breadth;
int height;
// Parametrised constructor
Box(int len,int bre,int hei){
length = len;
breadth = bre;
height = hei;
}
// Method
void volume(){
int volume = this->length*this->breadth*this->height;
cout << "The Volume of the Box is: " << volume << endl;
}
};
// this is a pointer which you can used to refer the instance
int main(){
Box b1(10,20,40);
cout << b1.length <<endl;
cout << b1.breadth <<endl;
cout << b1.height <<endl;
cout << first::x << endl;
cout << second::x << endl;
b1.volume();
return 0;
}