250+ TOP MCQs on Default Arguments and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Default Arguments”.

1. What are default arguments?
a) Arguments which are not mandatory to be passed
b) Arguments with default value that aren’t mandatory to be passed
c) Arguments which are not passed to functions
d) Arguments which always take same data value
Answer: b
Clarification: The arguments which are assigned with some default value. Since some value is already given, it is not mandatory to pass those arguments. They can be used directly.

2. Which is the correct condition for the default arguments?
a) Those must be declared as last arguments in argument list
b) Those must be declared first in the argument list
c) Those can be defined anywhere in the argument list
d) Those are declared inside the function definition
Answer: a
Clarification: The default arguments must be declared at last in the argument list. This is to ensure that the arguments doesn’t create ambiguity. The normal arguments should be passed first.

3. If a member function have to be made both zero argument and parameterized constructor, which among the following can be the best option?
a) Two normal and one default argument
b) At least one default argument
c) Exactly one default argument
d) Make all the arguments default
Answer: d
Clarification: All the arguments must be made default. This will make sure that none of the arguments are mandatory to be passed. Which in turn means that the function can work without any argument and can be passed with arguments too.

4. Which among the following function can be called without arguments?
a) void add(int x, int y=0)
b) void add(int=0)
c) void add(int x=0, int y=0)
d) void add(char c)
Answer: c
Clarification: For the function to be called without arguments, either it must have zero arguments or it must have all the default arguments. Here the function in option void add(int x=0, int y=0) have all the default arguments and hence can be called directly with zero argument.

5. If a function have all the default arguments but still some values are passed to the function then ______________
a) The function will use the values passed to it
b) The function will use the default values as those are local
c) The function can use any value whichever is higher
d) The function will choose the minimum values
Answer: a
Clarification: The function will use the values passed explicitly to it. The default values will be ignored. The default values are used only in case the values are not passed explicitly to the function.

6. Which among the following is correct?
a) void test(int x=0, int y, int z=0)
b) void test(int x=0, int=0)
c) void test(int x, int y=0)
d) void test(int x=’c, int y)
Answer: c
Clarification: The default arguments must be mentioned at last in the argument list. Also, the type of values assigned must match with the argument type. All the default arguments must be mentioned at last, none of the normal arguments should come in between the default arguments list.

7. What function will be called with the independent syntax “test(5,6,7);”?
a) void test(int x, int y)
b) void test(int x=0, int y, int z)
c) int test(int x=0, y=0, z=0)
d) void test(int x, int y, int z=0)
Answer: d
Clarification: There are three arguments that are getting passed to the function test(). Only the last option have all the default argument at last in the argument list. And the total number of the arguments is three. The third option is wrong because the return type is int and the syntax given is independent which means it doesn’t return any value.

8. Which among the following is a wrong call to the function void test(int x, int y=0, int z=0)?
a) test(5,6,7);
b) test(5);
c) test();
d) test(5,6);
Answer: c
Clarification: The function must be passed with at least one argument. There is two default arguments and one normal argument which must be passed with some value. Hence the third call to the function is wrong as it doesn’t pass even a single parameter to the function

9. Default arguments are _________________________
a) Only allowed in the parameter list of the function declaration
b) Only allowed in the return type of the function declaration
c) Only allowed with the class name definition
d) Only allowed with the integer type values
Answer: a
Clarification: The default arguments are only allowed in the parameter list of the function arguments. This rule was not applicable in the beginning versions of c++ but later from c++ 14th version it has been implemented. This is the only way to use default arguments.

10. Which among the following is false for default arguments?
a) Those are not allowed with a declaration of pointer to functions
b) Those are not allowed with the reference to functions
c) Those are not allowed with the typedef declarations
d) Those are allowed with pointer and reference to function declaration
Answer: d
Clarification: The statements given are true because that is a feature given to make the programming more flexible and have some security with accidental changes at same time. The last option is false because it is not a rule defined. It is an opposite statement to the rules defined for default arguments.

11. The non-template functions can be added with default arguments to already declared functions ____________________
a) If and only if the function is declared again in the same scope
b) If and only if the function is declared only once in the same scope
c) If and only if the function is declared in different scope
d) If and only if the function is declared twice in the program
Answer: a
Clarification: The non-template functions can also be added with default arguments. This can be done even if the functions were defined earlier. This is because the call to the function won’t be affected. The function can still be used in the same way as it was used earlier.

12. The using declaration __________
a) Doesn’t carry over the default values
b) Carries over the known default arguments
c) Carries over only the normal arguments
d) Carries over only few default arguments
Answer: b
Clarification: The using-declaration carries over all the known default arguments. This is a common feature as the usage doesn’t gets affected even if the default arguments are added. This comes under flexible programming.

13. The names given to the default arguments are only looked up and ________________ and are bound during declaration.
a) Checked for availability
b) Checked for random access
c) Checked for accessibility
d) Checked for feasibility
Answer: c
Clarification: The names given to the default arguments are bound at time of declaration but are only checked for accessibility and to get bounded. This is mainly to bind those members during declaration.

14. The default argument get bound during declaration ________________
a) And are never executed
b) And are executed simultaneously
c) But are executed only if priority is given
d) But are executed during function call
Answer: d
Clarification: The default argument are bound at the time of declaration. That is an implicit functioning. But those are executed only when the function is called. Otherwise, those will never get executed.

15. The virtual function overrides ____________
a) Do not acquire base class declaration of default arguments
b) Do acquire base class declaration of default arguments
c) Do not link with the default arguments of base class
d) Do link with the default argument but only of derived classes
Answer: a
Clarification: The virtual function overrides do not acquire the base class declaration of default arguments. Even if a call to the virtual function is made, static type of the object decides the default arguments to be used.

250+ TOP MCQs on Copy Constructor and Answers

Basic Object Oriented Programming Questions and Answers on “Copy Constructor”.

1. Copy constructor is a constructor which ________________
a) Creates an object by copying values from any other object of same class
b) Creates an object by copying values from first object created for that class
c) Creates an object by copying values from another object of another class
d) Creates an object by initializing it with another previously created object of same class
Answer: d
Clarification: The object that has to be copied to new object must be previously created. The new object gets initialized with the same values as that of the object mentioned for being copied. The exact copy is made with values.

2. The copy constructor can be used to ____________
a) Initialize one object from another object of same type
b) Initialize one object from another object of different type
c) Initialize more than one object from another object of same type at a time
d) Initialize all the objects of a class to another object of another class
Answer: a
Clarification: The copy constructor has the most basic function to initialize the members of an object with same values as that of some previously created object. The object must be of same class.

3. If two classes have exactly same data members and member function and only they differ by class name. Can copy constructor be used to initialize one class object with another class object?
a) Yes, possible
b) Yes, because the members are same
c) No, not possible
d) No, but possible if constructor is also same
Answer: c
Clarification: The restriction for copy constructor is that it must be used with the object of same class. Even if the classes are exactly same the constructor won’t be able to access all the members of another class. Hence we can’t use object of another class for initialization.

4. The copy constructors can be used to ________
a) Copy an object so that it can be passed to a class
b) Copy an object so that it can be passed to a function
c) Copy an object so that it can be passed to another primitive type variable
d) Copy an object for type casting
Answer: b
Clarification: When an object is passed to a function, actually its copy is made in the function. To copy the values, copy constructor is used. Hence the object being passed and object being used in function are different.

5. Which returning an object, we can use ____________
a) Default constructor
b) Zero argument constructor
c) Parameterized constructor
d) Copy constructor
Answer: d
Clarification: While returning an object we can use the copy constructor. When we assign the return value to another object of same class then this copy constructor will be used. And all the members will be assigned the same values as that of the object being returned.

6. If programmer doesn’t define any copy constructor then _____________
a) Compiler provides an implicit copy constructor
b) Compiler gives an error
c) The objects can’t be assigned with another objects
d) The program gives run time error if copying is used
Answer: a
Clarification: The compiler provides an implicit copy constructor. It is not mandatory to always create an explicit copy constructor. The values are copied using implicit constructor only.

7. If a class implements some dynamic memory allocations and pointers then _____________
a) Copy constructor must be defined
b) Copy constructor must not be defined
c) Copy constructor can’t be defined
d) Copy constructor will not be used
Answer: a
Clarification: In the case where dynamic memory allocation is used, the copy constructor definition must be given. The implicit copy constructor is not capable of manipulating the dynamic memory and pointers. Explicit definition allows to manipulate the data as required.

8. What is the syntax of copy constructor?
a) classname (classname &obj){ /*constructor definition*/ }
b) classname (cont classname obj){ /*constructor definition*/ }
c) classname (cont classname &obj){ /*constructor definition*/ }
d) classname (cont &obj){ /*constructor definition*/ }
Answer: c
Clarification: The syntax must contain the class name first, followed by the classname as type and &object within parenthesis. Then comes the constructor body. The definition can be given as per requirements.

9. Object being passed to a copy constructor ___________
a) Must be passed by reference
b) Must be passed by value
c) Must be passed with integer type
d) Must not be mentioned in parameter list
Answer: a
Clarification: This is mandatory to pass the object by reference. Otherwise, the object will try to create another object to copy its values, in turn a constructor will be called, and this will keep on calling itself. This will cause the compiler to give out of memory error.

10. Out of memory error is given when the object _____________ to the copy constructor.
a) Is passed with & symbol
b) Is passed by reference
c) Is passed as
d) Is not passed by reference
Answer: d
Clarification: All the options given, directly or indirectly indicate that the object is being passed by reference. And if object is not passed by reference then the out of memory error is produced. Due to infinite constructor call of itself.

11. Copy constructor will be called whenever the compiler __________
a) Generates implicit code
b) Generates member function calls
c) Generates temporary object
d) Generates object operations
Answer: c
Clarification: Whenever the compiler creates a temporary object, copy constructor is used to copy the values from existing object to the temporary object.

12. The deep copy is possible only with the help of __________
a) Implicit copy constructor
b) User defined copy constructor
c) Parameterized constructor
d) Default constructor
Answer: b
Clarification: While using explicit copy constructor, the pointers of copied object point to the intended memory location. This is assured since the programmers themselves manipulate the addresses.

13. Can a copy constructor be made private?
a) Yes, always
b) Yes, if no other constructor is defined
c) No, never
d) No, private members can’t be accessed
Answer: a
Clarification: The copy constructor can be defined as private. If we make it private then the objects of the class can’t be copied. It can be used when a class used dynamic memory allocation.

14. The arguments to a copy constructor _____________
a) Must be const
b) Must not be cosnt
c) Must be integer type
d) Must be static
Answer: a
Clarification: The object should not be modified in the copy constructor. Because the object itself is being copied. When the object is returned from a function, the object must be a constant otherwise the compiler creates a temporary object which can die anytime.

15. Copy constructors are overloaded constructors.
a) True
b) False
Answer: a
Clarification: The copy constructors are always overloaded constructors. They have to be. All the classes have a default constructor and other constructors are basically overloaded constructors.

To practice basic questions and answers on all areas of Object Oriented Programming,

250+ TOP MCQs on Object Use and Answers

Object Oriented Programming MCQs on “Object Use”.

1. Which among the following is the main use of object?
a) To create instance of a function
b) To create instance of a program
c) To create instance of class
d) To create instance of structures
Answer: c
Clarification: The objects are used to create an instance of a class. Objects can represent a class in an independent form. The basic blueprint, that contains the information of the type of data that can be stored in an object, is given by the class.

2. Which among the following is not a property of an object?
a) Identity
b) Properties
c) Attributes
d) Names
Answer: d
Clarification: The names are not property of an object. The identity can be in any form like address or name of object but name can’t be termed as only identity of an object. The objects contain attributes that define what type of data an object can store.

3. What is function object?
a) An object with a single function
b) An object with only functions
c) An object with more than one function
d) An object with no functions
Answer: a
Clarification: A function object is an object with single function. In C++ a function object can be like operator() function. This acts more like a function rather than an object.

4. Immutable object are used ______________________
a) To set up as a fixed state
b) To set up variable object
c) To set up an object of abstract class
d) To set up an object of derived class
Answer: a
Clarification: An immutable object can be created for an object which has to be fixed with values. The object data will not be changed throughout the program. This can be useful to eliminate the unintentional changes in the data of object.

5. Which object can be used to contain other objects?
a) First class object
b) Derived class object
c) Container object
d) Enclosure object
Answer: c
Clarification: A container object can be used to contain other objects. Container object is an ADT. Its object are collection of other objects. Some specific rules apply to these types of objects.

6. A factory object is used ______________________
a) To create new classes
b) To create new function
c) To create new data members
d) To create new objects
Answer:d
Clarification: The factory object is an object that can be used to create other objects. If it is seen formally, it behaves like a method that will return object on its use. The object returned is assumed to be a new object.

7. What are singleton objects?
a) The only two objects of a class throughout the program
b) The only object of a class throughout the program
c) The objects that are alive throughout the program
d) The objects that are created and then deleted without use
Answer: b
Clarification: If a class has only one object created and that is the only object of the class. Then the object is known as the singleton object. But only if that object is the only object of the class and no other object is created for that class.

8. Object cout and cin _________________
a) Can be used directly with << and >> symbols respectively
b) Can be used directly with >> and << symbols respectively
c) Must be used as a function which accepts 2 arguments
d) Must be used as a function which accepts 3 arguments
Answer: a
Clarification: The cin and cout objects can be used directly with the >> and << operators respectively. The objects are of iostream class. Class iostream is an inbuilt class.

9. Objects type ____________________
a) Can be changed in runtime
b) Can’t be changed in runtime
c) Can be changed in compile time
d) May or may not get changed
Answer: b
Clarification: The object types are always fixed. Once the object is created of a specific type then it can’t be changed. Neither at runtime nor at compile time.

10. An object can be used to represent _________________
a) A real world entity
b) A real function
c) Some real data only
d) Some function only
Answer: a
Clarification: The objects are actually meant to represent an entity. The classes are real world object’s blueprint. The classes then are used to create an entity representation.

11. Objects can be used _____________________
a) To access any member of a class
b) To access only public members of a class
c) To access only protected members of a class
d) To access only private members of a class
Answer: b
Clarification: The objects are created for a specific class. Then the objects can be used to access the public members of a class. The members can be the data members or the member functions of the class.

12. Which among the following is not a use of object?
a) Defining a member function
b) Accessing data members
c) Creating instance of a class
d) Using class members
Answer: a
Clarification: The objects can’t be used to define any member function. Member functions must be defined by the class only. Objects can only access the members and use them.

13. Which object can be used to access the standard input?
a) System.inner
b) cin
c) System.stdin
d) console.input
Answer: b
Clarification: Object cin can be used to take input from the standard input. It is used in C++. In java we can use System.in for the standard input stream. The syntax changes from language to language.

14. A single object can be used __________________
a) As only two class types at a time
b) As only three class types at a time
c) As only one class type at a time
d) As of as many class types as required
Answer: c
Clarification: The object can be of only one type. The type of an object can’t be changed. Object type is mandatory to be of one class type to ensure the type and number of data members it have.

15. If same object name is given to different objects of different class then _____________
a) Its compile time error
b) Its runtime error
c) It’s not an error
d) Program suns smooth
Answer: a
Clarification: It is a compile time error as the compiler doesn’t allow the same name objects to be declared more than once. Compiler produces multiple declaration errors. Every object must have a different name.

To practice MCQs on all areas of Object Oriented Programming,

250+ TOP MCQs on Member Operator Function and Answers

Object Oriented Programming Questions Aptitude test on “Member Operator Function”.

1. Which among the following are valid ways of overloading the operators?
a) Only using friend function
b) Only using member function
c) Either member functions or friend functions can be used
d) Operators can’t be overloaded
Answer: c
Clarification: The operators can be overloaded by using the member function or even the friend functions can be used. This is because both of these can access all the data members of a class.

2. Which among the following is mandatory condition for operators overloading?
a) Overloaded operator must be member function of the left operand
b) Overloaded operator must be member function of the right operand
c) Overloaded operator must be member function of either left or right operand
d) Overloaded operator must not be dependent on the operands
Answer: a
Clarification: The operator to be overloaded must be made the member function of the operand on left side of expressions to be used. This allows the compiler to identify whether the overloading has to be used or not. This rule also reduces the ambiguity in code.

3. When the operator to be overloaded becomes the left operand member then ______________
a) The right operand acts as implicit object represented by *this
b) The left operand acts as implicit object represented by *this
c) Either right or left operand acts as implicit object represented by *this
d) *this pointer is not applicable in that member function
Answer: b
Clarification: The left operand becomes the object that is referred by *this pointer in the member function that will be called while using operator overloading. This is done to point to a specific object on which the overloading will be applied.

4. If the left operand is pointed by *this pointer, what happens to other operands?
a) Other operands are passed as function return type
b) Other operands are passed to compiler implicitly
c) Other operands must be passed using another member function
d) Other operands are passed as function arguments
Answer: d
Clarification: The operands that are used during overloading expect the left operand, can be passed as function arguments. Those are then referred in function definition with the names specified in the argument list.

5. If a friend overloaded operator have to be changed to member overloaded operator, which operator should be used with the class name?
a) Scope resolution operator
b) Colon
c) Arrow operator
d) Dot operator
Answer: a
Clarification: The scope resolution operator can be used followed by the class name. Then the operator keyword with the operator symbol that should be overloaded. This is done to use member function instead of friend function.

6. What is the syntax to overload an operator?
a) className::operator(parameters)
b) className:operator(parameters)
c) className.operator(paramteres)
d) className->operator(parameters)
Answer: a
Clarification: The class name is followed by the scope resolution operator. This is done to specify the class to which the function should belong to. Then the keyword operator should be used in order to indicate the operator that is to be overloaded. Then come the parameters list to specify other operands.

7. Why the left parameter is removed from parameter list?
a) Because it is of no use
b) Because it is never used in definitions
c) Because it becomes parameter pointed by *this
d) Because it can’t be referred by *this pointer
Answer: c
Clarification: The left object is removed from being passed as a parameter, because it is implicitly passed. It is passed implicitly because it is considered the object with respect to which the overloading function is being called.

8. Which object’s members can be called directly while overloading operator function is used (In function definition)?
a) Left operand members
b) Right operand members
c) All operand members
d) None of the members
Answer: a
Clarification: This is because the left operand is passed implicitly. It is pointed by *this. This in turn means we can use the direct member names of the object because those are again converted to a syntax containing *this pointer implicitly.

9. If left operand member is specified directly in the function definition, which is the correct implicit conversion of that syntax?
a) *this className
b) *this parameterObject
c) *this returnedObject
d) *this object
Answer: d
Clarification: Since the left operands are passed implicitly, those object members can be accessed directly in the function definition. The compiler converts the syntax into the syntax that can be processed. The implicitly converted syntax contains *this pointer followed by the objectName that is left operand in the expression.

10. When the friend operator overloading is converted into member operator overloading _______________
a) Two parameters of friend function remains same parameters in member operator overloading
b) Two parameters of friend function becomes only one parameter of member function
c) Two parameters of friend function are removed while using member function
d) Two parameters of friend function are made 4 in member operator overloading
Answer: b
Clarification: The friend function would accept two arguments if some binary operator is overloaded. When we try to convert that definition to member operator overloading then it becomes only one parameter. The reason behind is that the left operand is passed implicitly while using the member functions.

11. Where in the parameter list is the implicit *this is added?
a) Right most parameter
b) Anywhere in parameter list
c) Left most parameter
d) Not added to parameter list
Answer: c
Clarification: The left operand is passed implicitly by the compiler to the member function. But this is done, when the compiler adds the calling object as *this to the parameter list. It is always added as the left most parameter, i.e. the first parameter of the function.

12. Which operator among the following can be overloading using only member function?
a) Assignment operator
b) Addition operator
c) Subtraction operator
d) Multiplication and division operator
Answer: a
Clarification: Only the assignment operator among the options given must be overloaded using the member functions. The assignment operator can’t be overloaded using friend function. This is a restriction in the programming languages to make the programs more resistant towards errors.

13. Which operator among the following can be overloaded using both friend function and member function?
a) Assignment operator
b) Subscript
c) Member selection (arrow operator)
d) Modulus operator
Answer: d
Clarification: Only the modulus operator among the given operators can be overloaded using either friend function or member function. Other operators must be overloaded using only the member functions.

14. All the operators can be overloaded using the member function operator overloading.
a) True
b) False
Answer: b
Clarification: It is not the case that all the operators can be overloaded using the member operator overloading. There are some cases where the operators must be overloaded using the friend function only. The reason behind is that the left operand should be passed *this pointer, but the left operand in these cases might be object of some other class. Hence can’t be done.

15. Which operator among the following must be overloaded using the friend function?
a) << operator only
b) >> operator only
c) Both << and >> operators
d) It’s not mandatory to use friend function in any case
Answer: c
Clarification: In some cases it is mandatory to use the friend functions for overloading the operators. Here both the > operators must be overloaded using friend function because the left operand is object of some other class and the right operand is usually of some different type.

250+ TOP MCQs on Constructors Overloading and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Constructors Overloading”.

1. Which among the following is true for constructors overloading?
a) Constructors can’t be overloaded
b) Constructors can be overloaded using different signatures
c) Constructors can be overloaded with same signatures
d) Constructors can be overloaded with different return types
Answer: b
Clarification: The constructors can be overloaded only if the definitions have different signatures. Constructors doesn’t have any return type so can’t be overloaded using return type. If constructors have same signature then it will produce a compile time error.

2. If a constructors should be capable of creating objects without argument and with arguments, which is a good alternative for this purpose?
a) Use zero argument constructor
b) Use constructor with one parameter
c) Use constructor with all default arguments
d) Use default constructor
Answer: c
Clarification: The constructor should use all the default arguments. This will allow the constructor to be called even if no arguments are passed. And if arguments are passed, those will be accepted instead of the default values.

3. The Constructors with all the default arguments are similar as default constructors.
a) True
b) False
Answer: a
Clarification: The constructors with all the default arguments are similar as the default constructors. Those can be used instead of the default constructors. So defining the default constructor is not mandatory.

4. Which among the following is true?
a) The constructors overloading can be done by using different names
b) The constructors overloading can be done by using different return types
c) The constructors can be overloaded by using only one argument
d) The constructors must have the same name as that of class
Answer: d
Clarification: The constructors must have the same name as that of the class name. This is mandatory because only the constructor functions doesn’t have any return type. Also, for overloading all the functions must have the same name.

5. Which among the following can be used in place of default constructor?
a) constructorName(int x, int y=0)
b) constructorName(int x=0, int y=0)
c) constructorName(int x=0, int y)
d) constructorName(int x, int y)
Answer: b
Clarification: For a parameterized constructor to be used as a default constructor, it must have all the default arguments. This makes the constructor to have optional arguments which are not mandatory to be passed.

6. Can a class have more than one function with all the default arguments?
a) Yes, always
b) Yes, if argument list is different
c) No, because constructors overloading doesn’t depend on argument list
d) No, never
Answer: d
Clarification: A single class can never have more than once constructor with all the default arguments. This is because it will make all those constructors as a default constructor. And when an object is created with zero arguments then it will create ambiguity.

7. 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()
Answer: c
Clarification: The constructors using the default arguments must initialize the arguments in the argument list. This is to make the constructor use the default value when no arguments are passed. If no arguments are listed then it is a default constructor.

8. 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
Answer: b
Clarification: In the prototype given, only 2 arguments are mandatory. Since the third argument is default argument, so it is not mandatory to pass the argument.

9. 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
Answer: a
Clarification: The constructors having same arguments except the default arguments can give rise to errors. If only the mandatory arguments are passed, it will create ambiguity in calling the correct constructor. Hence the mandatory arguments must be different.

10. 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
Answer: d
Clarification: The constructors must have different argument list. Along that, if all the arguments are default arguments, there can’t be more than once constructor like that in the same class as that will create ambiguity while constructors are being called.

11. 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);
Answer: a
Clarification: The syntax given is passing two parameters to the constructor call. One value is of integer type and another of character type. Hence the constructor with arguments of int and char type should be called. There is only one option that first accepts integer value and then a character value. Hence that constructor will be called.

12. 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);
Answer: c
Clarification: The default arguments, just like with member functions, must be listed at last in the argument list. Hence this will produce a compile time error. The compiler doesn’t allow the definition to be executed.

13. 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
Answer: c
Clarification: The constructors will use the default values listed for use. The null values are not used because those are not specified. Though if it was compiler provided default constructor, then it would have initialized the members to null or zero values.

14. 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
Answer: d
Clarification: The closest answer to the question is that a default constructor is a constructor with zero arguments. But this is not the actual case. Actually the constructors provided by the compiler are default constructors. And the constructors with zero arguments defined by the programmer are zero argument constructors.

15. 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
Answer: b
Clarification: The constructor with one default argument can be the best alternative. This is because the constructor with one default value will do the work for both the default constructor and one argument constructor.

250+ TOP MCQs on Overloading Constructors and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Overloading Constructors”.

1. Which among the following best describes constructor overloading?
a) Defining one constructor in each class of a program
b) Defining more than one constructor in single class
c) Defining more than one constructor in single class with different signature
d) Defining destructor with each constructor
Answer: c
Clarification: If more than one constructors are defined in a class with same signature, then that results in error. The signatures must be different. So that the constructors can be differentiated.

2. Can constructors be overloaded in derived class?
a) Yes, always
b) Yes, if derived class has no constructor
c) No, programmer can’t do it
d) No, never
Answer: d
Clarification: The constructor must be having the same name as that of a class. Hence a constructor of one class can’t even be defined in another class. Since the constructors can’t be defined in derived class, it can’t be overloaded too, in derived class.

3. Does constructor overloading include different return types for constructors to be overloaded?
a) Yes, if return types are different, signature becomes different
b) Yes, because return types can differentiate two functions
c) No, return type can’t differentiate two functions
d) No, constructors doesn’t have any return type
Answer: d
Clarification: The constructors doesn’t have any return type. When we can’t have return type of a constructor, overloading based on the return type is not possible. Hence only parameters can be different.

4. Which among the following is possible way to overload constructor?
a) Define default constructor, 1 parameter constructor and 2 parameter constructor
b) Define default constructor, zero argument constructor and 1 parameter constructor
c) Define default constructor, and 2 other parameterized constructors with same signature
d) Define 2 default constructors
Answer: a
Clarification: All the constructors defined in a class must have a different signature in order to be overloaded. Here one default and other parameterized constructors are used, wherein one is of only one parameter and other accepts two. Hence overloading is possible.

5. Which constructor will be called from the object created in the code below?

class A
{ 
	int i;
	A()
	{ 
		i=0; cout&lt;&lt;i; 
	}
	A(int x=0)
	{ 
		i=x;  cout&lt;&lt;I;  
	}
};
A obj1;

a) Default constructor
b) Parameterized constructor
c) Compile time error
d) Run time error
Answer: c
Clarification: When a default constructor is defined and another constructor with 1 default value argument is defined, creating object without parameter will create ambiguity for the compiler. The compiler won’t be able to decide which constructor should be called, hence compile time error.

6. Which among the following is false for a constructor?
a) Constructors doesn’t have a return value
b) Constructors are always user defined
c) Constructors are overloaded with different signature
d) Constructors may or may not have any arguments being accepted
Answer: b
Clarification: The constructors are not always user defined. The construct will be provided implicitly from the compiler if the used doesn’t defined any constructor. The implicit constructor makes all the string values null and allocates memory space for each data member.

7. When is the constructor called for an object?
a) As soon as overloading is required
b) As soon as class is derived
c) As soon as class is created
d) As soon as object is created
Answer: d
Clarification: The constructor is called as soon as the object is created. The overloading comes into picture as to identify which constructor have to be called depending on arguments passed in the creation of object.

8. Which among the following function can be used to call default constructor implicitly in java?
a) this()
b) that()
c) super()
d) sub()
Answer: a
Clarification: The function this() can be used to call the default constructor from inside any other constructor. This helps to further reuse the code and not to write the redundant data in all the constructors.

9. Why do we use constructor overloading?
a) To use different types of constructors
b) Because it’s a feature provided
c) To initialize the object in different ways
d) To differentiate one constructor from another
Answer: c
Clarification: The constructors are overloaded to initialize the objects of a class in different ways. This allows us to initialize the object with either default values or used given values. If data members are not initialized then program may give unexpected results.

10. If programmer have defined parameterized constructor only, then __________________
a) Default constructor will not be created by the compiler implicitly
b) Default constructor will be created by the compiler implicitly
c) Default constructor will not be created but called at runtime
d) Compile time error
Answer: a
Clarification: When the programmer doesn’t specify any default constructor and only defines some parameterized constructor. The compiler doesn’t provide any default constructor implicitly. This is because it is assumed that the programmer will create the objects only with constructors.

11. Which among the following is not valid in java?
a) Constructor overloading
b) Recursive constructor call
c) Default value constructors
d) String argument constructor
Answer: b
Clarification: Java doesn’t provide the feature to recursively call the constructor. This is to eliminate the out of memory error in some cases that arises unexpectedly. That is an predefined condition for constructors in java.

12. Which constructor will be called from the object obj2 in the following program?

class A
{
	int i;
	A()
	{  
		i=0;  
	}
	A(int x)
	{  
		i=x+1;  
	}
	A(int y, int x)
	{  
		i=x+y;  
	}
};
A obj1(10);
A obj2(10,20);
A obj3;

a) A(int x)
b) A(int y)
c) A(int y, int x)
d) A(int y; int x)
Answer: c
Clarification: The two argument constructor will be called as we are passing 2 arguments to the object while creation. The arguments will be passed together and hence compiler resolves that two argument constructor have to be called.

13. What are we only create an object but don’t call any constructor for it in java?
a) Implicit constructor will be called
b) Object is initialized to some null values
c) Object is not created
d) Object is created but points to null
Answer: d
Clarification: The object becomes a reference object which can be initialized will another object. Then this object will indirectly become another name of the object being assigned. If not assigned, it simply points to null address.

14. Which among the following is false?
a) Constructor can’t be overloaded in Kotlin
b) Constructors can’t be called recursively in java
c) Constructors can be overloaded in C++
d) Constructors overloading depends on different signatures
Answer: a
Clarification: Kotlin language allows constructor overloading. This is a basic feature for the constructors. The constructor overloading allows the object to be initialized according to the user.

15. Which is correct syntax?
a) classname objectname= new() integer;
b) classname objectname= new classname;
c) classname objectname= new classname();
d) classname objectname= new() classname();
Answer: c
Clarification: The syntax for object creating in java with calling a constructor for is it is as in option c. The syntax must contain the classname followed by the object name. The keyword new must be used and then the constructor call with or without the parameters as required.