forked from anishsingh20/Programming-in-Cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructorOverloading.cpp
More file actions
58 lines (42 loc) · 822 Bytes
/
constructorOverloading.cpp
File metadata and controls
58 lines (42 loc) · 822 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
58
//constructors example
#include<iostream>
using namespace std;
class human
{
public:
human() {
age=10;
name="Anish";
cout<<"Default Constructor is called"<<endl;
}
human(int iage=19,string iname="Mrinal") {
age=iage;
name=iname;
cout<<"overloaded constructor called"<<endl;
}
void introduce()
{
cout<<"Hello I am" <<" " << name << " "<<"and my age is" << age<<endl;
}
/* /int getage()
{
cin>>age;
return age;
}
string getName()
{
cin>>name;
return name;
}*/
private:
int age;
string name;
};
int main() {
human obj;//constructor is called as soon as an object is created
//default constructor called
obj.introduce();
human obj2;//arguments passed to the object
//constructor overloaded
obj2.introduce();
}