Prepare
Practice
Interview
Aptitude
Reasoning
English
GD
Placement papers
HR
Current affairs
Engineering
MCA
MBA
Online test
Login
Define a constructor with default arguments - Constructor and Destructor
Home
>>
Category
>>
C++ (MCQ) questions and answers
>>
Constructor and Destructor
Q. Is it possible to define a constructor with default arguments?
- Published on 19 Jul 15
a.
Yes
b.
No
ANSWER: Yes
Related Content
Constructor and Destructor (
10
)
Operator Overloading (
11
)
Inheritance (
16
)
Polymorphism and Abstract Classes (
12
)
C++ basic concepts (
39
)
Exception Handling (
22
)
File Handling (
11
)
Functions (
20
)
Memory Management (
6
)
Pointers (
3
)
Discussion
Nihal
-Posted on 08 Oct 15
You can define a constructor with default arguments. You can call a constructor without passing all its parameter but you have to specify default values when the constructor is declared.
Example:
class student
{
int roll_no;
float std_marks;
public:
student(int a=10,float b=50)
{
roll_no=a;
std_marks=b;
}
void display()
{
cout<<"Roll no: "<
cout<<"Marks: "<
}
};
void main()
{
student s1;
student s2(1,60);
clrscr();
cout<<"\n Output using default constructor arguments:\n";
s1.display();
cout<<"\n Output without using default constructor arguments:\n";
s2.display();
getch();
}
➨
Post your comment / Share knowledge
Required!
Required!
Invalid Email Id!
Required!
Enter the code shown above:
Please enter the code shown above
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)
MCQs
English
Tutorials
Download
▲