OBJECT ORIENTED PROGRAMMING MCQ's SET-5




1. In how many ways can an object be passed to a function? 

a) 1 

b) 2 

c) 3 

d) 4 

Answer: c 


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 values 

Answer: a 


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, explicitly 

 Answer: c 


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 also 

 Answer: a 


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 used 

 Answer: b 


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 member 

 Answer: a 


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 exceptions 

 Answer: c 

 

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 constructor 

 Answer: d 

 

9. How many objects can be returned at once? 

a) Only 1 

b) Only 2 

c) Only 16 

d) As many as required 

Answer: a


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 explicitly 

 Answer: c 


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 required 

Answer: d 


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 created 

 Answer: c 


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 different 

 Answer: a 


14. Passing an object using copy constructor and pass by value are same. 

a) True 

b) False

 Answer: b


15. What is reference to an object? 

a) It is address of an object 

b) It is address of where the variables and methods of object are stored 

c) It is pointer having address of an object 

d) It is address of only variables and not the methods of an object 

 Answer: b 

Explanation: Reference indicates the address where the object’s variables and methods are stored. It is not actual address of the object. This is done to directly use the variables and methods whenever required. advertisement 

17. Whenever an object is assigned to a variable or passed to a method ________________ 

a) Actually the objects aren’t used 

b) Actually only the objects are used 

c) Actually a pointer to an object is used 

d) Actually copy of object is used 

Answer: a 


18. Does use of object reference in assignment or passing means copy of the object is being used? 

a) No, because the copy would create a new temporary variable 

b) No, because the copy would not help to make changes to main object 

c) Yes, because the reference directly means using address 

d) Yes, because the reference directly means the constructors are involved 

 Answer: c 


19. Is there any explicit use of pointers in java that would be applicable to objects? 

a) Yes, we use reference for this purpose 

b) Yes, we use java arrays for this purpose 

c) No, implicit pointing is possible 

d) No, direct class names should be used 

 Answer: c 


20. Can a super class object give reference to a subclass method? 

a) No, it is not possible 

b) Maybe, it is possible 

c) No, it’s not possible 

d) No, It’s not possible in few cases only 

 Answer: c






Popular Posts