Computer Science - Object Oriented Programming Using C++ - Discussion
Discussion Forum : Object Oriented Programming Using C++ - Section 2 (Q.No. 29)
29.
If you want to override constructor default values for an object you are instantiating, you must also override
Discussion:
4 comments Page 1 of 1.
Jasminder singh said:
1 year ago
The default paramters are ser like this in any function in c++.
class Demo{
// constructor.
Demo(int a, int b = 0, int c = 0) {
// code here.
}
};
If we want to override the default parameters of the constructor we need also override or pass the argument to the left values for example look below.
Demo obj = new Demo(1,2,3);
we also set the first parameter of the constructor otherwise it will throw an exception or error.
class Demo{
// constructor.
Demo(int a, int b = 0, int c = 0) {
// code here.
}
};
If we want to override the default parameters of the constructor we need also override or pass the argument to the left values for example look below.
Demo obj = new Demo(1,2,3);
we also set the first parameter of the constructor otherwise it will throw an exception or error.
Riddhi said:
5 years ago
Please explain the answer.
Meenakshi said:
1 decade ago
Please explain this answer?
Aman said:
1 decade ago
Please explain this answer in detail.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers