Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Which among the following is called first, automatically, whenever an object is created?(a) Class(b) Constructor(c) New(d) TriggerI had been asked this question in class test.My enquiry is from Constructors in portion Constructors and Destructors of Object Oriented Programming

Answer»

Correct choice is (B) Constructor

The best explanation: Constructors are the MEMBER functions which are called automatically WHENEVER an object is created. It is a mandatory functions to be called for an object to be created as this helps in initializing the object to a LEGAL initial value for the class.

2.

Which among the following is not a necessary condition for constructors?(a) Its name must be same as that of class(b) It must not have any return type(c) It must contain a definition body(d) It can contains argumentsI have been asked this question in an online interview.This intriguing question comes from Constructors topic in section Constructors and Destructors of Object Oriented Programming

Answer» RIGHT option is (c) It must CONTAIN a DEFINITION body

The explanation is: Constructors are predefined implicitly, even if the programmer doesn’t define any of them. Even if the programmer declares a CONSTRUCTOR, it’s not necessary that it must contain some definition.
3.

Which among the following is correct?(a) class student{ public: int student(){} };(b) class student{ public: void student (){} };(c) class student{ public: student{}{}};(d) class student{ public: student(){} };I had been asked this question in an interview for internship.Asked question is from Constructors topic in portion Constructors and Destructors of Object Oriented Programming

Answer»

Right option is (d) class STUDENT{ public: student(){} };

Explanation: The constructors must not have any RETURN type. Also, the body may or may not contain any body. Defining DEFAULT constructor is optional, if you are not USING any other constructor.

4.

In which access should a constructor be defined, so that object of the class can be created in any function?(a) Public(b) Protected(c) Private(d) Any access specifier will workI got this question in an international level competition.Question is taken from Constructors topic in division Constructors and Destructors of Object Oriented Programming

Answer» CORRECT answer is (a) Public

The explanation: Constructor function should be available to all the parts of PROGRAM where the OBJECT is to be created. Hence it is ADVISED to define it in public ACCESS, so that any other function is able to create objects.
5.

How many types of constructors are available for use in general (with respect to parameters)?(a) 2(b) 3(c) 4(d) 5I got this question in class test.My question comes from Constructors in portion Constructors and Destructors of Object Oriented Programming

Answer»

Correct answer is (a) 2

To explain: TWO types of CONSTRUCTORS are defined GENERALLY, namely, default constructor and parameterized constructor. Default constructor is not NECESSARY to be defined always.

6.

Default constructor must be defined, if parameterized constructor is defined and the object is to be created without arguments.(a) True(b) FalseI got this question during an online exam.This interesting question is from Constructors in section Constructors and Destructors of Object Oriented Programming

Answer» RIGHT answer is (a) True

To explain I would say: If the object is create without arguments and only parameterized CONSTRUCTORS are used, COMPILER will give an error as there is no DEFAULT constructor defined. And some constructor must be called so as to create an object in MEMORY.
7.

If class C inherits class B. And B has inherited class A. Then while creating the object of class C, what will be the sequence of constructors getting called?(a) Constructor of C then B, finally of A(b) Constructor of A then C, finally of B(c) Constructor of C then A, finally B(d) Constructor of A then B, finally CThe question was asked at a job interview.My question comes from Constructors topic in section Constructors and Destructors of Object Oriented Programming

Answer»

The correct answer is (d) CONSTRUCTOR of A then B, finally C

The explanation is: While creating the OBJECT of CLASS C, its constructor would be CALLED by DEFAULT. But, if the class is inheriting some other class, firstly the parent class constructor will be called so that all the data is initialized that is being inherited.

8.

Which among the following is true for copy constructor?(a) The argument object is passed by reference(b) It can be defined with zero arguments(c) Used when an object is passed by value to a function(d) Used when a function returns an objectI have been asked this question in an online quiz.The origin of the question is Constructors topic in division Constructors and Destructors of Object Oriented Programming

Answer»

Right ANSWER is (B) It can be defined with zero arguments

Easiest explanation - It can’t be defined with zero number of arguments. This is because to copy ONE OBJECT to another, the object must be mentioned so that COMPILER can take values from that object.

9.

If the object is passed by value to a copy constructor?(a) Only public members will be accessible to be copied(b) That will work normally(c) Compiler will give out of memory error(d) Data stored in data members won’t be accessibleI have been asked this question in quiz.My doubt is from Constructors topic in section Constructors and Destructors of Object Oriented Programming

Answer»

The CORRECT choice is (c) Compiler will give out of memory error

The explanation is: Compiler runs out of memory. This is because while PASSING the argument by VALUE, a constructor of the OBJECT will be called. That in turn called another object constructor for values, and this GOES on. This is like a constructor call to itself, and this goes on infinite times, hence it must be passed by reference, so that the constructor is not called.

10.

Which among the following helps to create a temporary instance?(a) Implicit call to a default constructor(b) Explicit call to a copy constructor(c) Implicit call to a parameterized constructor(d) Explicit call to a constructorThe question was posed to me in an interview.My enquiry is from Constructors in section Constructors and Destructors of Object Oriented Programming

Answer» RIGHT ANSWER is (d) Explicit CALL to a constructor

Explanation: Explicit call to a constructor can LET you create a temporary instance. This is because the temporary instances doesn’t have any name. Those are DELETED from memory as soon as their reference is removed.
11.

For constructor overloading, each constructor must differ in ___________ and __________(a) Number of arguments and type of arguments(b) Number of arguments and return type(c) Return type and type of arguments(d) Return type and definitionThe question was asked during an interview.My enquiry is from Constructors in division Constructors and Destructors of Object Oriented Programming

Answer»

Right option is (a) Number of arguments and type of arguments

For EXPLANATION: Each CONSTRUCTOR must DIFFER in the number of arguments it accepts and the type of arguments. This actually defines the constructor signature. This helps to remove the AMBIGUITY and define a unique constructor as REQUIRED.

12.

How many types of constructors are available, in general, in any language?(a) 2(b) 3(c) 4(d) 5This question was posed to me in my homework.I'm obligated to ask this question of Types of Constructors in portion Constructors and Destructors of Object Oriented Programming

Answer»

Correct option is (b) 3

Explanation: There are 3 types of CONSTRUCTORS in general, namely, default constructors, PARAMETERIZED constructors and copy constructors. Default ONE is called whenever an object is CREATED without arguments.

13.

Which constructor is called while assigning some object with another?(a) Default(b) Parameterized(c) Copy(d) Direct assignment is usedThis question was posed to me during an online exam.My query is from Types of Constructors in section Constructors and Destructors of Object Oriented Programming

Answer»

Right CHOICE is (C) Copy

Easiest EXPLANATION - Copy constructor is used while an object is assigned with ANOTHER. This is mandatory since we can’t decide which member should be assigned to which member value. By using copy constructor, we can assign the values in REQUIRED form.

14.

It’s necessary to pass object by reference in copy constructor because ____________(a) Constructor is not called in pass by reference(b) Constructor is called in pass by reference only(c) It passes the address of new constructor to be created(d) It passes the address of new object to be createdI have been asked this question in an online quiz.My question comes from Types of Constructors topic in chapter Constructors and Destructors of Object Oriented Programming

Answer»

The correct option is (a) CONSTRUCTOR is not called in pass by reference

For explanation: Object must be passed by reference to copy constructor because constructor is not called in pass by reference. Otherwise, in pass by VALUE, a temporary object will be created which in turn will try to call its constructor that is ALREADY being used. This results in CREATING infinite NUMBER of objects and hence memory shortage error will be shown.

15.

Which specifier applies only to the constructors?(a) Public(b) Protected(c) Implicit(d) ExplicitI got this question during a job interview.My enquiry is from Types of Constructors in section Constructors and Destructors of Object Oriented Programming

Answer»

The correct choice is (d) Explicit

The best I can explain: The KEYWORD explicit can be USED while DEFINING the constructor only. This is used to SUPPRESS the implicit call to the constructor. It ensures that the CONSTRUCTORS are being called with the default syntax only (i.e. only by using object and constructor name).

16.

Which among the following is true?(a) Default constructor can’t be defined by the programmer(b) Default parameters constructor isn’t equivalent to the default constructor(c) Default constructor can be called explicitly(d) Default constructor is and always called implicitly onlyThis question was posed to me during an interview.I'd like to ask this question from Types of Constructors topic in section Constructors and Destructors of Object Oriented Programming

Answer»

Right answer is (c) Default constructor can be CALLED explicitly

Easiest explanation - Default constructors can be called explicitly ANYTIME. They are specifically used to ALLOCATE memory space for the object in memory, in general. It is not necessary that these should ALWAYS be called implicitly.

17.

Which type of constructor can’t have a return type?(a) Default(b) Parameterized(c) Copy(d) Constructors don’t have a return typeThis question was posed to me in an international level competition.Asked question is from Types of Constructors in portion Constructors and Destructors of Object Oriented Programming

Answer»

Correct option is (d) Constructors don’t have a return TYPE

Explanation: Constructors don’t return any value. Those are special functions, WHOSE return type is not defined, not even void. This is so because the constructors are meant to initialize the members of CLASS and not to perform some task which can return some value to NEWLY CREATED object.

18.

Why do we use static constructors?(a) To initialize the static members of class(b) To initialize all the members with static value(c) To delete the static members when not required(d) To clear all the static members initialized valuesI got this question in semester exam.My query is from Types of Constructors topic in portion Constructors and Destructors of Object Oriented Programming

Answer» RIGHT option is (a) To initialize the STATIC members of CLASS

For explanation: Static constructors help in initializing the static members of the class. This is PROVIDED because the static members are not considered to be property of the object, rather they are considered as the property of class.
19.

When and how many times a static constructor is called?(a) Created at time of object destruction(b) Called at first time when an object is created and only one time(c) Called at first time when an object is created and called with every new object creation(d) Called whenever an object go out of scopeI have been asked this question during an interview for a job.My question is from Types of Constructors in division Constructors and Destructors of Object Oriented Programming

Answer» RIGHT option is (B) Called at first time when an object is CREATED and only one time

The explanation: Those are called at very first CALL of object creation. That is called only one time because the value of static MEMBERS must be retained and continued from the time it gets created.
20.

Which among the following is true for static constructor?(a) Static constructors are called with every new object(b) Static constructors are used initialize data members to zero always(c) Static constructors can’t be parameterized constructors(d) Static constructors can be used to initialize the non-static members alsoI got this question in class test.The doubt is from Types of Constructors in portion Constructors and Destructors of Object Oriented Programming

Answer»

The correct CHOICE is (c) STATIC constructors can’t be parameterized constructors

The BEST I can explain: Static constructors can’t be parameterized constructors. Those are used to INITIALIZE the value of static members only. And that must be a definite value. Accepting arguments may MAKE it possible that static members loses their value with every new object being created.

21.

Within a class, only one static constructor can be created.(a) True(b) FalseI got this question in an interview.My question is from Types of Constructors topic in chapter Constructors and Destructors of Object Oriented Programming

Answer»

The correct option is (a) True

Explanation: Since the STATIC constructors are can’t be parameterized, they can’t be OVERLOADED. Having this CASE, only one constructor will be possible to be created in a local scope, because the signature will always be same and hence it will not be possible to overload static constructor.

22.

Default constructor initializes all data members as ___________(a) All numeric member with some garbage values and string to random string(b) All numeric member with some garbage values and string to null(c) All numeric member with zero and strings to random value(d) All numeric member with zero and strings to nullI got this question during an interview.This intriguing question comes from Types of Constructors in portion Constructors and Destructors of Object Oriented Programming

Answer»

Right choice is (d) All NUMERIC member with zero and strings to null

To EXPLAIN: Default constructor, which even the programmer doesn’t define, always initialize the values as zero if numeric and null if string. This is DONE so as to avoid the ACCIDENTAL values to change the conditional statements being used and similar conditions.

23.

When is the static constructor called?(a) After the first instance is created(b) Before default constructor call of first instance(c) Before first instance is created(d) At time of creation of first instanceI had been asked this question in a job interview.My question is taken from Types of Constructors in division Constructors and Destructors of Object Oriented Programming

Answer» RIGHT choice is (c) Before FIRST instance is created

The best explanation: The static constructor is called before creation of the first instance of that class. This is DONE so that even the first instance can use the static value of the static members of the class and manipulate as required.
24.

If constructors of a class are defined in private access, then __________(a) The class can’t be inherited(b) The class can be inherited(c) Instance can be created only in another class(d) Instance can be created anywhere in the programI have been asked this question in an online interview.The origin of the question is Types of Constructors in portion Constructors and Destructors of Object Oriented Programming

Answer»

Right choice is (a) The CLASS can’t be inherited

The best I can explain: If the CONSTRUCTORS are defined in private access, then the class can’t be inherited by other classes. This is useful when the class contains static members only. The INSTANCES can NEVER be CREATED.

25.

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 classI got this question in unit test.My question is from Copy Constructor in portion Constructors and Destructors of Object Oriented Programming

Answer»

Correct option is (d) Creates an OBJECT by initializing it with ANOTHER PREVIOUSLY created object of same class

Easy explanation - 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.

26.

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 classThe question was posed to me in semester exam.This intriguing question originated from Copy Constructor in division Constructors and Destructors of Object Oriented Programming

Answer»

Right CHOICE is (a) Initialize one object from another object of same type

Explanation: 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.

27.

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 sameThis question was addressed to me during a job interview.I want to ask this question from Copy Constructor in chapter Constructors and Destructors of Object Oriented Programming

Answer»

The correct answer is (c) No, not possible

Easiest explanation - 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.

28.

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 castingThe question was asked during a job interview.The above asked question is from Copy Constructor topic in chapter Constructors and Destructors of Object Oriented Programming

Answer»

The correct option is (B) Copy an OBJECT so that it can be passed to a function

The explanation is: 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.

29.

Which returning an object, we can use ____________(a) Default constructor(b) Zero argument constructor(c) Parameterized constructor(d) Copy constructorI have been asked this question in an interview.Question is taken from Copy Constructor topic in portion Constructors and Destructors of Object Oriented Programming

Answer» RIGHT ANSWER is (d) Copy constructor

The EXPLANATION: 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.
30.

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 usedThis question was addressed to me in homework.This is a very interesting question from Copy Constructor in section Constructors and Destructors of Object Oriented Programming

Answer»

The CORRECT choice is (a) Compiler provides an implicit copy CONSTRUCTOR

To explain I would SAY: 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.

31.

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 usedI got this question in a national level competition.The origin of the question is Copy Constructor topic in portion Constructors and Destructors of Object Oriented Programming

Answer»

Correct CHOICE is (a) Copy constructor must be defined

The best explanation: 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.

32.

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*/ }This question was posed to me during an interview.This is a very interesting question from Copy Constructor in portion Constructors and Destructors of Object Oriented Programming

Answer»

The correct choice is (c) CLASSNAME (cont classname &obj){ /*constructor definition*/ }

To explain: 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.

33.

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 listI got this question in my homework.The question is from Copy Constructor in portion Constructors and Destructors of Object Oriented Programming

Answer»

Right answer is (a) Must be passed by REFERENCE

Explanation: 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.

34.

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 referenceThe question was asked by my college professor while I was bunking the class.The query is from Copy Constructor in division Constructors and Destructors of Object Oriented Programming

Answer»

Right answer is (d) Is not passed by reference

Easiest explanation - 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.

35.

Copy constructor will be called whenever the compiler __________(a) Generates implicit code(b) Generates member function calls(c) Generates temporary object(d) Generates object operationsThe question was asked in homework.My doubt stems from Copy Constructor in chapter Constructors and Destructors of Object Oriented Programming

Answer»

Correct option is (c) GENERATES TEMPORARY object

To EXPLAIN: Whenever the compiler creates a temporary object, COPY constructor is used to copy the VALUES from existing object to the temporary object.

36.

The deep copy is possible only with the help of __________(a) Implicit copy constructor(b) User defined copy constructor(c) Parameterized constructor(d) Default constructorI got this question in examination.Query is from Copy Constructor in section Constructors and Destructors of Object Oriented Programming

Answer»

Correct choice is (B) USER defined copy constructor

The best explanation: 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.

37.

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 accessedI had been asked this question at a job interview.The doubt is from Copy Constructor topic in section Constructors and Destructors of Object Oriented Programming

Answer»

The correct choice is (a) Yes, always

Easy explanation - 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.

38.

The arguments to a copy constructor _____________(a) Must be const(b) Must not be cosnt(c) Must be integer type(d) Must be staticThis question was addressed to me in an online quiz.The origin of the question is Copy Constructor in division Constructors and Destructors of Object Oriented Programming

Answer»

The CORRECT ANSWER is (a) Must be const

To explain I would say: 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.

39.

Copy constructors are overloaded constructors.(a) True(b) FalseThis question was addressed to me during a job interview.The question is from Copy Constructor in chapter Constructors and Destructors of Object Oriented Programming

Answer»

The CORRECT option is (a) True

The best EXPLANATION: 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.

40.

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 constructorI got this question in a national level competition.Query is from Overloading Constructors topic in portion Constructors and Destructors of Object Oriented Programming

Answer»

Right answer is (c) DEFINING more than one constructor in single CLASS with different signature

For explanation: 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.

41.

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, neverThis question was addressed to me during an interview for a job.The query is from Overloading Constructors topic in division Constructors and Destructors of Object Oriented Programming

Answer»

The correct OPTION is (d) No, never

Easy explanation - 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.

42.

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 typeI got this question by my school principal while I was bunking the class.The query is from Overloading Constructors topic in portion Constructors and Destructors of Object Oriented Programming

Answer» CORRECT CHOICE is (d) No, constructors doesn’t have any return type

To explain I would say: 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.
43.

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 constructorsThe question was posed to me in examination.This key question is from Overloading Constructors in chapter Constructors and Destructors of Object Oriented Programming

Answer» CORRECT answer is (a) DEFINE default constructor, 1 parameter constructor and 2 parameter constructor

The explanation: 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.
44.

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 acceptedThis question was addressed to me during an interview for a job.The origin of the question is Overloading Constructors topic in portion Constructors and Destructors of Object Oriented Programming

Answer»

Right answer is (B) Constructors are always USER defined

For explanation: 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.

45.

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 createdThis question was posed to me during an internship interview.My question comes from Overloading Constructors topic in section Constructors and Destructors of Object Oriented Programming

Answer»

The CORRECT option is (d) As SOON as OBJECT is created

Explanation: 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.

46.

Which among the following function can be used to call default constructor implicitly in java?(a) this()(b) that()(c) super()(d) sub()The question was posed to me in an interview for job.My question comes from Overloading Constructors in portion Constructors and Destructors of Object Oriented Programming

Answer» RIGHT answer is (a) this()

Explanation: 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.
47.

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 anotherThe question was asked in an online interview.My doubt stems from Overloading Constructors topic in chapter Constructors and Destructors of Object Oriented Programming

Answer»

Right choice is (c) To INITIALIZE the object in DIFFERENT ways

Explanation: 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.

48.

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 errorI had been asked this question during an interview for a job.My question is based upon Overloading Constructors topic in section Constructors and Destructors of Object Oriented Programming

Answer»

Right choice is (a) Default CONSTRUCTOR will not be CREATED by the compiler implicitly

To explain I would SAY: 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.

49.

Which among the following is not valid in java?(a) Constructor overloading(b) Recursive constructor call(c) Default value constructors(d) String argument constructorI got this question during a job interview.I'd like to ask this question from Overloading Constructors topic in portion Constructors and Destructors of Object Oriented Programming

Answer» RIGHT CHOICE is (b) Recursive constructor call

To EXPLAIN I would say: 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.
50.

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 nullThe question was asked in quiz.My query is from Overloading Constructors in section Constructors and Destructors of Object Oriented Programming

Answer»

Correct choice is (d) Object is created but POINTS to null

The best explanation: 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.