Which among the following is true for the code given below? [code] class A { private : int marks; char name[20]; public : A(int x=100) {

Which among the following is true for the code given below?
Code:
class A
{
	private : int marks; char name[20];
	public :
	A(int x=100)
	{ 
		marks=x;  
	}
};
A. Objects can be created with one parameter or without parameter
B. Object can be created only with one parameter
C. Object can be created with more than one parameter
D. Objects can be create only without parameter
 
Answer: a
Explanation: The constructor here has a default argument constructor. Hence we can pass one parameter, but that is optional. If an object is created without parameter, the default value will be used in the constructor definition.
 

Tìm kiếm

Back
Top