Skip to content

Commit 9b5c9ee

Browse files
authored
Merge pull request #817 from pushpakumari5117/issue-794
Added the code for Parameterized Constructor in C++
2 parents c0e1612 + ba2c827 commit 9b5c9ee

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// C++ program to demonstrate Parameterized Constructor
2+
3+
// Parameterized Constructor - A constructor which has parameters is known as Parameterized Constructor. It is
4+
// used to provide different values to distinct objects.
5+
6+
#include<bits/stdc++.h>
7+
using namespace std;
8+
9+
// class with Parameterized Constructor
10+
class Person{
11+
private:
12+
string name;
13+
int age;
14+
public:
15+
Person(string iname,int iage){
16+
name=iname;
17+
age=iage;
18+
}
19+
void display(){
20+
cout<<"Name : "<<name<<endl;
21+
cout<<"Age : "<<age<<endl;
22+
}
23+
};
24+
25+
int main(){
26+
// Creating an object of class Person
27+
Person p("abc",10);
28+
p.display();
29+
return 0;
30+
}

0 commit comments

Comments
 (0)