InterviewSolution
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 |
|
| 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(){} }; |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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*/ } |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|