-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_oops.cpp
More file actions
35 lines (31 loc) · 859 Bytes
/
10_oops.cpp
File metadata and controls
35 lines (31 loc) · 859 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
#include<iostream>
using namespace std;
class complex{
int a,b;
public:
// create a constructor
//constructor is a special member function with same name of the class.
//it is used to initialize the object of its class
//it is automatically invoked whenever an ojbect is created
complex(void); // constructor declaration
void printNumber(){
cout<<" your complex is"<<a<<" + "<<b<<"i"<<endl;
}
};
complex :: complex(void){ //-->default constructor as it take no parameters
a=10;
b=6;
}
int main(){
complex c1,c2,c3;
c1.printNumber();
c2.printNumber();
c2.printNumber();
return 0;
}
/*characteristics of constructors
1. It should be declered in the public section of the class.
2. they cannot return value and do not have return type.
3. it can have default arguments.
4. we can't refer to their address.
*/