-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassesAndObject.cpp
More file actions
executable file
·58 lines (47 loc) · 1.27 KB
/
Copy pathClassesAndObject.cpp
File metadata and controls
executable file
·58 lines (47 loc) · 1.27 KB
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
58
#include <iostream>
using namespace std;
class Hero {
private:
// By default data members of a class are private - i.e. you can access the private properties only inside class using getter & setter methods that are public
int health;
public:
// All the public data members can be accessed inside as well as outside a class
char name;
int age;
int getHealth() {
return health;
}
void setHealth(int h) {
this->health = h;
}
Hero(char name, int age) {
name = name;
age = age;
}
void print_details() {
cout << "name: " << name << endl;
cout << "age: " << age << endl;
}
// Hero() {
// cout << "Removed default constructor after creating a user-defined constructors" << endl;
// }
// static const int justValue = 1999;
static const int justValue = 1999;
};
int main() {
// Creation an object
// Hero Sam;
// Hero Ron ("B", 75);
cout << Hero::justValue << endl;
cout << "Output" << endl;
// Sam.name = 'A';
// Sam.age = 90;
// Sam.setHealth(95);
// cout << "Hero Sam Health: " << Sam.getHealth() << endl;
// cout << "Hero Sam name: " << Sam.name << endl;
// cout << "Hero Sam age: " << Sam.age << endl;
// cout << "Hero Ron name: " << (*Ron).name << endl;
// cout << "Hero Ron age: " << Ron->age << endl;
// Ron.print_details();
return 0;
}