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;
		i=0; cout<<i; 
	A(int x=0)
		i=x;  cout<<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(int x)
	A(int y, int x)
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.

Leave a Reply

Your email address will not be published. Required fields are marked *