File tree 2 files changed +52
-2
lines changed
2 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ class human
13
13
cout<<" Default Constructor is called" <<endl;
14
14
}
15
15
16
- human (int iage,string iname) {
16
+ human (int iage= 19 ,string iname= " Mrinal " ) {
17
17
age=iage;
18
18
name=iname;
19
19
cout<<" overloaded constructor called" <<endl;
@@ -51,7 +51,7 @@ int main() {
51
51
// default constructor called
52
52
obj.introduce ();
53
53
54
- human obj2 ( 20 , " mrinal " ) ;// arguments passed to the object
54
+ human obj2;// arguments passed to the object
55
55
// constructor overloaded
56
56
57
57
obj2.introduce ();
Original file line number Diff line number Diff line change
1
+ // constructors example
2
+ #include < iostream>
3
+
4
+ using namespace std ;
5
+
6
+
7
+ class human
8
+ {
9
+ public:
10
+
11
+ // default values of the constructor params
12
+ human (int iage=19 ,string iname=" Mrinal" ) {
13
+ age=iage;
14
+ name=iname;
15
+ cout<<" Object created with default constructor values" <<endl;
16
+ }
17
+
18
+ void introduce ()
19
+ {
20
+ cout<<" Hello I am" <<" " << name << " " <<" and my age is" << age<<endl;
21
+ }
22
+
23
+ /* /int getage()
24
+ {
25
+ cin>>age;
26
+ return age;
27
+
28
+ }
29
+ string getName()
30
+ {
31
+
32
+ cin>>name;
33
+ return name;
34
+
35
+ }*/
36
+
37
+ private:
38
+ int age;
39
+ string name;
40
+
41
+
42
+ };
43
+
44
+
45
+ int main () {
46
+ human obj;// constructor is called as soon as an object is created
47
+ obj.introduce ();
48
+
49
+
50
+ }
You can’t perform that action at this time.
0 commit comments