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.

In how many ways can an object be passed to a function?(a) 1(b) 2(c) 3(d) 4I have been asked this question during an internship interview.I'm obligated to ask this question of Passing and Returning Object with Functions topic in division Object of Object Oriented Programming

Answer»

The correct choice is (c) 3

Best EXPLANATION: The OBJECTS can be passed in three WAYS. Pass by VALUE, pass by reference and pass by address. These are the general ways to pass the objects to a function.

2.

If an object is passed by value _____________(a) A new copy of object is created implicitly(b) The object itself is used(c) Address of the object is passed(d) A new object is created with new random valuesThe question was asked in unit test.The above asked question is from Passing and Returning Object with Functions in section Object of Object Oriented Programming

Answer»

Right answer is (a) A NEW copy of object is CREATED IMPLICITLY

The explanation is: When an object is PASSED by value, a new object is created implicitly. This new object uses the implicit values assignment, same as that of the object being passed.

3.

Pass by address passes the address of object _________ and pass by reference passes the address of the object _________(a) Explicitly, explicitly(b) Implicitly, implicitly(c) Explicitly, Implicitly(d) Implicitly, explicitlyI got this question by my college professor while I was bunking the class.The doubt is from Passing and Returning Object with Functions in chapter Object of Object Oriented Programming

Answer» RIGHT answer is (c) Explicitly, IMPLICITLY

Explanation: Pass by address USES the EXPLICIT address passing to the FUNCTION whereas pass by reference implicitly passes the address of the object.
4.

If an object is passed by reference, the changes made in the function ___________(a) Are reflected to the main object of caller function too(b) Are reflected only in local scope of the called function(c) Are reflected to the copy of the object that is made during pass(d) Are reflected to caller function object and called function object alsoI have been asked this question in a job interview.Question is taken from Passing and Returning Object with Functions topic in section Object of Object Oriented Programming

Answer»

The correct choice is (a) Are REFLECTED to the main OBJECT of caller function too

The best I can EXPLAIN: When an object is PASSED by REFERENCE, its address is passed implicitly. This will make changes to the main function whenever any modification is done.

5.

Constructor function is not called when an object is passed to a function, will its destructor be called when its copy is destroyed?(a) Yes, depending on code(b) Yes, must be called(c) No, since no constructor was called(d) No, since same object gets usedThe question was posed to me in an international level competition.I would like to ask this question from Passing and Returning Object with Functions topic in portion Object of Object Oriented Programming

Answer»

Correct option is (b) Yes, MUST be called

To explain: EVEN THOUGH the constructor is not called when the object is passed to a FUNCTION, the copy of the object is still created, where the values of the members are same. When the object have to be destroyed, the destructor is called to free the MEMORY and resources that the object might have reserved.

6.

When an object is returned by a function, a _______________ is automatically created to hold the return value.(a) Temporary object(b) Virtual object(c) New object(d) Data memberThe question was posed to me at a job interview.I want to ask this question from Passing and Returning Object with Functions topic in division Object of Object Oriented Programming

Answer» CORRECT answer is (a) TEMPORARY object

Easy explanation - The temporary object is created. It holds the return value. The VALUES gets assigned as REQUIRED, and the temporary object gets destroyed.
7.

Is the destruction of temporary object safe (while returning object)?(a) Yes, the resources get free to use(b) Yes, other objects can use the memory space(c) No, unexpected side effects may occur(d) No, always gives rise to exceptionsThis question was posed to me in an interview for job.Question is from Passing and Returning Object with Functions in section Object of Object Oriented Programming

Answer» CORRECT choice is (c) No, unexpected side EFFECTS MAY occur

Best explanation: The destruction of temporary variable may GIVE rise to unexpected logical errors. Consider the destructor which may free the dynamically allocated memory. But this may abort the program if another is still trying to copy the values from that dynamic memory.
8.

How to overcome the problem arising due to destruction of temporary object?(a) Overloading insertion operator(b) Overriding functions can be used(c) Overloading parenthesis or returning object(d) Overloading assignment operator and defining copy constructorI got this question in semester exam.Origin of the question is Passing and Returning Object with Functions topic in division Object of Object Oriented Programming

Answer»

The correct OPTION is (d) Overloading assignment operator and defining copy constructor

Explanation: The problem can be SOLVED by overloading the assignment operator to get the values that might be getting returned while the destructor free the dynamic memory. Defining copy constructor can help us to do this in EVEN simpler way.

9.

How many objects can be returned at once?(a) Only 1(b) Only 2(c) Only 16(d) As many as requiredI had been asked this question in a job interview.This question is from Passing and Returning Object with Functions topic in portion Object of Object Oriented Programming

Answer»

The CORRECT option is (a) Only 1

Easiest explanation - LIKE any other VALUE, only one object can be returned at ones. The only POSSIBLE way to return more than one object is to return address of an object array. But that again comes under returning object pointer.

10.

It is necessary to return the object if it was passed by reference to a function.(a) Yes, since the object must be same in caller function(b) Yes, since the caller function needs to reflect the changes(c) No, the changes are made automatically(d) No, the changes are made explicitlyThis question was addressed to me in an internship interview.My query is from Passing and Returning Object with Functions topic in division Object of Object Oriented Programming

Answer»

The correct option is (c) No, the changes are MADE automatically

The explanation: Having the address being PASSED to the function, the changes are automatically made to the main function. In all the cases if the address is being used, the same memory LOCATION will be UPDATED with NEW values.

11.

How many objects can be passed to a function simultaneously?(a) Only 1(b) Only an array(c) Only 1 or an array(d) As many as requiredThe question was posed to me in an interview for internship.I want to ask this question from Passing and Returning Object with Functions in division Object of Object Oriented Programming

Answer»

Correct option is (d) As many as required

The EXPLANATION is: There is no limit to how many objects can be PASSED. This works in same way as that any other VARIABLE GETS passed. Array and object can be passed at same time ALSO.

12.

If an object is passed by address, will be constructor be called?(a) Yes, to allocate the memory(b) Yes, to initialize the members(c) No, values are copied(d) No, temporary object is createdThe question was posed to me in final exam.This question is from Passing and Returning Object with Functions in section Object of Object Oriented Programming

Answer»

The correct option is (c) No, values are copied

Best explanation: A copy of all the values is CREATED. If the constructor is called, there will be a compile time ERROR or memory shortage. This happens because each time a constructor is called, it TRY to call itself again and that goes infinite TIMES.

13.

Is it possible that an object of is passed to a function, and the function also have an object of same name?(a) No, Duplicate declaration is not allowed(b) No, 2 objects will be created(c) Yes, Scopes are different(d) Yes, life span is differentI have been asked this question in my homework.This interesting question is from Passing and Returning Object with Functions in section Object of Object Oriented Programming

Answer»

Correct CHOICE is (a) No, DUPLICATE declaration is not allowed

Easy explanation - There can’t be more than one VARIABLE or object with the same NAME in same scope. The scope is same, since the object is passed, it becomes local to FUNCTION and hence function can’t have one more object of same name.

14.

Passing an object using copy constructor and pass by value are same.(a) True(b) FalseThis question was posed to me in an online quiz.This question is from Passing and Returning Object with Functions topic in portion Object of Object Oriented Programming

Answer»

Correct option is (B) False

To explain: The copy constructor is used to copy the VALUES from ONE object to other. PASS by values is not same as copy constructor method. Actually the pass by value method uses a copy constructor to copy the values in a LOCAL object.

15.

If a reference variable is declared final then _________________(a) It can never be reassigned to refer to a different object(b) It can be assigned to refer to any object anytime(c) It can never be assigned with any object(d) It can be assigned with 2 or more objects simultaneouslyI have been asked this question by my college director while I was bunking the class.The doubt is from Object Reference in division Object of Object Oriented Programming

Answer»

The correct choice is (a) It can never be reassigned to REFER to a different object

Easiest explanation - Since the VARIABLE is declared FINAL. It will have a CONSTANT value throughout the program. It can refer to only ONE object at a time. And if it was made to refer to none of the object, it would have got no use.

16.

Which of the members are referred by this pointer usually (Java)?(a) Members of class where this is used(b) Member of the parent class where this is used(c) Members that are passed as argument to the object(d) Pointers are not applicable in javaThe question was asked in a job interview.This intriguing question comes from Object Reference topic in division Object of Object Oriented Programming

Answer»

Correct option is (a) MEMBERS of class where this is USED

Explanation: We use this pointer to differentiate the members of the class where this is used to the other INHERITED or passed variables. The LOCAL variables are denoted with this. Or SPECIFICALLY the members of class only.

17.

How to refer to method of nested class?(a) enclosingClassObject.innerClassObject.method();(b) innerClassObject.method();(c) method();(d) depends on where the method is being calledThis question was posed to me in an online quiz.This question is from Object Reference topic in portion Object of Object Oriented Programming

Answer»

The correct option is (d) depends on where the method is being called

Explanation: This depends on where the method is being called. If the method is called inside the enclosing class itself. Then we can’t USE OBJECT of enclosing class. If the method is being called WITHIN the inner class itself, then its object will ALSO be of no use.

18.

How many objects can be referenced from the same variables?(a) One at a time(b) Many at a time(c) Many using array name(d) 7 at max at same timeI had been asked this question in unit test.I want to ask this question from Object Reference topic in chapter Object of Object Oriented Programming

Answer»

Right CHOICE is (a) One at a time

For EXPLANATION: There should not be any CONFUSION in how many references can be made from a single variable. A single variable can only point to one object at a time. EVEN if it’s an ARRAY, the name of the array is used and is considered one object name only (representing first array element).

19.

Java handles memory dynamically and references are deleted as soon as they are out of scope.(a) True(b) FalseThis question was posed to me in an international level competition.This key question is from Object Reference topic in portion Object of Object Oriented Programming

Answer»

Right option is (a) True

To explain: In Java, it is inbuilt feature that HANDLES all the memory dynamically. It is not necessary to free or DESTROY all the REFERENCES MADE from a FUNCTION which is going out of scope. You can call destroy or free methods explicitly but there is no mandatory rule.

20.

Which among the following is true?(a) Object referencing refers to methods address(b) Object referencing refers to variable of object(c) Object referencing points to same address, if assigned by variables(d) Object referencing is used to point methodsThe question was asked in an interview for internship.I'm obligated to ask this question of Object Reference in portion Object of Object Oriented Programming

Answer»

Correct choice is (c) Object REFERENCING points to same address, if assigned by variables

Explanation: The object referencing will POINT to the same address if variables are assigned. All the variables might have a DIFFERENT name but they will point to the same memory location. This is most basic concept of references.

21.

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 smoothI got this question by my college professor while I was bunking the class.This interesting question is from Object Use topic in section Object of Object Oriented Programming

Answer»

Correct answer is (a) Its compile time error

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

22.

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 requiredI had been asked this question during a job interview.I need to ask this question from Object Use in chapter Object of Object Oriented Programming

Answer»

Correct answer is (c) As only one class TYPE at a time

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

23.

Which object can be used to access the standard input?(a) System.inner(b) cin(c) System.stdin(d) console.inputThe question was posed to me at a job interview.My enquiry is from Object Use topic in division Object of Object Oriented Programming

Answer»

Correct OPTION is (b) cin

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

24.

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 membersThis question was posed to me in a job interview.The doubt is from Object Use topic in section Object of Object Oriented Programming

Answer» CORRECT option is (a) DEFINING a member function

Best explanation: 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.
25.

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 classThe question was asked in an internship interview.The query is from Object Use in section Object of Object Oriented Programming

Answer» CORRECT option is (b) To access only public MEMBERS of a class

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

An object can be used to represent _________________(a) A real world entity(b) A real function(c) Some real data only(d) Some function onlyI got this question in an internship interview.This is a very interesting question from Object Use in division Object of Object Oriented Programming

Answer»

The correct answer is (a) A REAL world entity

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

27.

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 changedI had been asked this question in examination.The question is from Object Use topic in division Object of Object Oriented Programming

Answer»

The correct option is (b) Can’t be CHANGED in runtime

Best EXPLANATION: 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.

28.

Object cout and cin _________________(a) Can be used directly with > symbols respectively(b) Can be used directly with >> and

Answer»

The correct ANSWER is (a) Can be used directly with << and >> symbols respectively

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

29.

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 useI had been asked this question in examination.My enquiry is from Object Use topic in division Object of Object Oriented Programming

Answer»

The CORRECT option is (B) The only object of a class THROUGHOUT the program

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

30.

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 objectsThis question was posed to me in a national level competition.The above asked question is from Object Use topic in portion Object of Object Oriented Programming

Answer»

Correct choice is (d) To CREATE new objects

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

31.

Which object can be used to contain other objects?(a) First class object(b) Derived class object(c) Container object(d) Enclosure objectI had been asked this question during an online exam.My enquiry is from Object Use topic in portion Object of Object Oriented Programming

Answer» CORRECT answer is (c) Container OBJECT

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

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 classThe question was asked in an online quiz.Origin of the question is Object Use topic in chapter Object of Object Oriented Programming

Answer»

The correct CHOICE is (a) To set up as a fixed state

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

33.

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 functionsThis question was addressed to me during an online exam.Enquiry is from Object Use in chapter Object of Object Oriented Programming

Answer»

The CORRECT CHOICE is (a) An object with a single function

The best I can explain: 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.

34.

Which among the following is not a property of an object?(a) Identity(b) Properties(c) Attributes(d) NamesThe question was asked in examination.I need to ask this question from Object Use topic in section Object of Object Oriented Programming

Answer»

The CORRECT answer is (d) NAMES

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

35.

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 structuresThe question was asked in unit test.This intriguing question originated from Object Use in section Object of Object Oriented Programming

Answer»
36.

Is an array of characters always a string?(a) Yes, always(b) Yes, if each character is terminated by null(c) No, since each character is terminated by null(d) No, neverI got this question by my school principal while I was bunking the class.This interesting question is from Object Array topic in chapter Object of Object Oriented Programming

Answer»

Correct answer is (d) No, never

The explanation is: The character arrays are not the same as STRING. The string once CREATED then remains the same. The character array values MAY change.

37.

Two dimensional array can’t be initialized with the declaration.(a) True(b) FalseI have been asked this question in unit test.Enquiry is from Object Array in portion Object of Object Oriented Programming

Answer»

The correct choice is (B) False

Explanation: The TWO dimensional arrays can also be initialized using curly brackets. For each set, values in curly bracket. And then another bracket is ADDED at first and end. This ENSURES that all the code BELONGS to the user.

38.

From which index does the array of objects start?(a) 0(b) 1(c) 2(d) 3This question was addressed to me during an online exam.Query is from Object Array topic in division Object of Object Oriented Programming

Answer»

Right choice is (a) 0

For EXPLANATION: The index must START from 0. The index ends at SIZE – 1 index. This is because the index is ALWAYS TILL n-1 where n is the total number of beads.

39.

Can we have two dimensional object array?(a) Yes, always(b) Yes, only if primitive type array(c) No, since two indices are impossible(d) No, neverI had been asked this question in a national level competition.The above asked question is from Object Array in section Object of Object Oriented Programming

Answer»

Correct ANSWER is (a) YES, always

Explanation: A two DIMENSIONAL array can always be created. There is no rule that only PRIMITIVE type objects can have more than one dimension. The object array can also be made 2 dimensional.

40.

If an array of objects is of size 10 and a data value have to be retrieved from 5th object then ________________ syntax should be used.(a) Array_Name[4].data_variable_name;(b) Data_Type Array_Name[4].data_variable_name;(c) Array_Name[4].data_variable_name.value;(d) Array_Name[4].data_variable_name(value);The question was asked in examination.My doubt stems from Object Array topic in portion Object of Object Oriented Programming

Answer»

Correct answer is (a) Array_Name[4].data_variable_name;

The explanation is: The array NAME with the index of fifth element is CALLED, i.e. index 4. Then the dot operator is USED to access the data member of that OBJECT. This Allows us to access the data members of all the objects in an object array.

41.

The Object array is created in _____________________(a) Heap memory(b) Stack memory(c) HDD(d) ROMThe question was asked during a job interview.My question is from Object Array topic in division Object of Object Oriented Programming

Answer»

The correct option is (a) HEAP memory

To explain I would SAY: If the object arrays are DECLARED dynamically, then the memory will be reserved on heap. The memory for objects will be on stack only if some constructor or some call and RETURN tasks are happening. The program doesn’t run on HDD and ROM is not used for the execution of PROGRAMS.

42.

The objects in an object array _______________________(a) Can be created without use of constructor(b) Can be created without calling default constructor(c) Can’t be created with use of constructor(d) Can’t be created without calling default constructorThe question was asked in unit test.I would like to ask this question from Object Array topic in portion Object of Object Oriented Programming

Answer»

Right answer is (b) Can be created WITHOUT calling default CONSTRUCTOR

The explanation is: The objects need some constructor to get the memory spaced reserved for those. If the default constructor is not used then we can use some ARGUMENTS constructor which will RESERVE the memory for the objects. The objects can be passed with constructor arguments during declaration.

43.

How the objects of array can be denoted?(a) Indices(b) Name(c) Random numbers(d) AlphabetsThe question was asked in an online interview.I'd like to ask this question from Object Array topic in chapter Object of Object Oriented Programming

Answer»

The correct OPTION is (a) Indices

To explain I would say: Different objects in an array can be DENOTED with the indices of array. The first object is denoted by 0. And the further indices DENOTE the NEXT objects in sequence of array.

44.

If constructor arguments are passed to objects of array then ____________ if the constructors are overloaded.(a) It is mandatory to pass same number of arguments to all the objects(b) It is mandatory to pass same type of arguments to all the objects(c) It is not mandatory to call same constructor for all the objects(d) It is mandatory to call same constructor for all the constructorsThe question was asked during an online interview.My question comes from Object Array topic in chapter Object of Object Oriented Programming

Answer»

Correct answer is (C) It is not mandatory to call same constructor for all the objects

The best I can explain: It is not mandatory to call the same constructor for all the objects in an array if INITIALIZED with the declaration. The objects can be passed with DIFFERENT set of arguments in the same SYNTAX, separated by commas.

45.

When are the array of objects without any initialization useful?(a) When object data is not required just after the declaration(b) When initialization of object data is to be made by the compiler(c) When object data doesn’t matter in the program(d) When the object should contain garbage dataThe question was asked in an international level competition.This intriguing question originated from Object Array in division Object of Object Oriented Programming

Answer»

The correct option is (a) When object data is not REQUIRED just after the declaration

The explanation: Sometimes the object data is not mandatory to be used just after the declaration or may be the program REQUIRES the data to be updated ACCORDING to what USER inputs. Hence only declaration us also useful.

46.

Which is the condition that must be followed if the array of objects is declared without initialization, only with size of array?(a) The class should have separate constructor for each object(b) The class must have no constructors(c) The class should not have any member function(d) The class must have a default or zero argument constructorThis question was addressed to me during an interview.My question is from Object Array topic in division Object of Object Oriented Programming

Answer»

The correct answer is (d) The class MUST have a default or zero argument constructor

Explanation: The class must have a default/zero argument constructor. Since the declaration is done by only specifying the size of ARRAY, the class must have default a construct to be called by default to reserve MEMORY for each object. Also, we can’t specify the ARGUMENTS in this type of declaration HENCE the class should provide a default initialization.

47.

What is the type of elements of array of objects?(a) Class(b) Void(c) String(d) NullI had been asked this question in my homework.This intriguing question originated from Object Array topic in division Object of Object Oriented Programming

Answer»

The CORRECT answer is (a) Class

To explain I would say: The class itself is the type of elements of array of OBJECTS. All the objects possess the same properties. Like any other PRIMITIVE DATA type, the objects are of their respective class type.

48.

Which among the following is a mandatory condition for array of objects?(a) All the objects should be of different class(b) All the objects should be of same program classes(c) All the objects should be of same class(d) All the objects should have different dataThis question was posed to me during an interview.The above asked question is from Object Array topic in division Object of Object Oriented Programming

Answer»

Right choice is (C) All the OBJECTS should be of same CLASS

To explain: The objects of an array must be of same class. This is mandatory because array is set of same type of elements. The objects of same class are considered to be of same type.

49.

What is an array of objects?(a) An array of instances of class represented by single name(b) An array of instances of class represented by more than one name(c) An array of instances which have more than 2 instances(d) An array of instances which have different typesThis question was addressed to me in homework.My question is based upon Object Array topic in division Object of Object Oriented Programming

Answer»

Correct CHOICE is (a) An ARRAY of instances of class represented by single name

The best I can explain: The array of objects an array of instances of a class. The array is represented by a single name. The array name is itself a pointer. Array name REPRESENTS the FIRST OBJECT.

50.

Which operator can be used to free the memory allocated for an object in C++?(a) Free()(b) delete(c) Unallocate(d) CollectThe question was asked in a national level competition.Asked question is from Memory Allocation of Object in portion Object of Object Oriented Programming

Answer»

Correct ANSWER is (b) delete

The best explanation: The delete operator in C++ can be used to FREE the memory and resources held by an object. The function can be called EXPLICITLY whenever REQUIRED. In C++ memory management must be done by the programmer. There is no automatic memory management in C++.