A directory of Objective Type Questions covering all the Computer Science subjects. Here you can access and discuss Multiple choice questions and answers for various compitative exams and interviews.

21. Which is the correct syntax for using default arguments with the constructor?
a. default constructorName(default int x=0)
b. constructorName(default int x=0)
c. constructorName(int x=0)
d. constructorName()
View Answer Report Discuss Too Difficult!
Answer: (c).constructorName(int x=0)

22. How many parameters must be passed if only the following prototype is given to a constructor?

Prototype: className(int x, int y, int z=0);
a. 1
b. 2
c. 3
d. Compile time error
View Answer Report Discuss Too Difficult!
Answer: (b).2

23. If the constructors are overloaded by using the default arguments, which problem may arise?
a. The constructors might have all the same arguments except the default arguments
b. The constructors might have same return type
c. The constructors might have same number of arguments
d. The constructors can’t be overloaded with respect to default arguments
View Answer Report Discuss Too Difficult!
Answer: (a).The constructors might have all the same arguments except the default arguments

24. Which among the following is true ?
a. More than one constructors with all default arguments is allowed
b. More than one constructors with all default arguments can be defined outside the class
c. More than one constructors can be used with same argument list
d. More than one constructors with all default arguments can’t exist in same class
View Answer Report Discuss Too Difficult!
Answer: (d).More than one constructors with all default arguments can’t exist in same class

25. Which constructor among the following will be called if a call is made like className(5,’a’);?
a. className(int x=5,char c=’a’);
b. int className(int x, char c, char d);
c. className(int x, char c, int y);
d. char className(char c,int x);
View Answer Report Discuss Too Difficult!
Answer: (a).className(int x=5,char c=’a’);

26. Which constructor definition will produce a compile time error?
a. className(int x=0);
b. className(char c);
c. className(int x=0,char c);
d. className(char c,int x=0);
View Answer Report Discuss Too Difficult!
Answer: (c).className(int x=0,char c);

27. If there is a constructor with all the default arguments and arguments are not passed then _________________
a. The default values given will not be used
b. Then all the null values will be used
c. Then all the default values given will be used
d. Then compiler will produce an error
View Answer Report Discuss Too Difficult!
Answer: (c).Then all the default values given will be used

28. Which is the correct statement for default constructors?
a. The constructors with all the default arguments
b. The constructors with all the null and zero values
c. The constructors which can’t be defined by programmer
d. The constructors with zero arguments
View Answer Report Discuss Too Difficult!
Answer: (d).The constructors with zero arguments

29. Which is a good alternative instead of having one zero argument constructor and one single argument constructor with default argument?
a. No constructor defined
b. One default value constructor
c. Defining the default constructor
d. Using one constructor with two arguments
View Answer Report Discuss Too Difficult!
Answer: (b).One default value constructor

30. What is upcasting?
a. Casting subtype to supertype
b. Casting super type to subtype
c. Casting subtype to super type and vice versa
d. Casting anytype to any other type
View Answer Report Discuss Too Difficult!
Answer: (a).Casting subtype to supertype

Page 3 of 6