Recently MeroSpark is lunched with more features and services, now you can ask your question, sell your books, share your notes and many more. Visit now and create your account to take full advantage of MeroSpark.

Parametrized Constructor – Object Oriented Programming (OOP)

Download our Android App from Google Play Store and start reading Reference Notes Offline.

parametrized constructorParametrized Constructor – Reference Note
Object Oriented Programming (OOP)
Third Semester | Second year
BSc.CSIT | Tribhuvan University (TU)

Parameterized Constructor
We can write a constructor in C++ which can accept parameters for its invocation. Such constructor that can take arguments are called parameterized constructor. In other words; “Declaring a constructor with arguments hides the default constructor”. This means that we can always specify the arguments whenever we declare an instance of the class. To illustrate parameterized constructor well, let us write the syntax and take one example;


class classname
classname(arguments);       //parametrized constructor

Now let us take one example;
class student
char name[20];
int rno;
student(char, int);       //parametrized constructor
student::student(char n, int r)

In the above example parameterized constructor has been shown by comment line. When the constructor is parameterized, we must provide appropriate arguments for the constructor.

(Visited 182 times, 1 visits today)

Posted By : Digvijay | Comment RSS | Category : Third Semester
Tag :

Post a Comment

Your email is never published nor shared. Required fields are marked *


Wordpress DMCA
Community | Toolbar | Android App | Founder/Developer : Hari Prasad Chaudhary | CSIT Portal Manager : Digvijay Chaudhary