Test Series - oops

Test Number 63/78

Q: Passing object to a function _______________
A. Can be done only in one way
B. Can be done in more than one ways
C. Is not possible
D. Is not possible in OOP
Solution: The objects can be passed to the functions and this requires OOP concept because objects are main part of OOP. The objects can be passed in more than one way to a function. The passing depends on how the object have to be used.
Q: If object is passed by value ______________
A. Copy constructor is used to copy the values into another object in the function
B. Copy constructor is used to copy the values into temporary object
C. Reference to the object is used to access the values of the object
D. Reference to the object is used to created new object in its place
Solution: The copy constructor is used. This constructor is used to copy the values into a new object which will contain all the values same as that of the object being passed but any changes made to the newly created object will not affect the original object.
Q: Copy constructor definition requires __________________
A. Object to be passed by value
B. Object not to be passed to it
C. Object to be passed by reference
D. Object to be passed with each data member value
Solution: The object must be passed by reference to a copy constructor. This is to avoid the out of memory error. The constructors keeps calling itself, if not passed by reference, and goes out of memory.
Q: Pass by reference of an object to a function _______________
A. Affects the object in called function only
B. Affects the object in prototype only
C. Affects the object in caller function
D. Affects the object only if mentioned with & symbol with every call
Solution: The original object in the caller function will get affected. The changes made in the called function will be same in the caller function object also.
Q: What is the type of object that should be specified in the argument list?
A. Function name
B. Object name itself
C. Caller function name
D. Class name of object
Solution: The type of object is the class itself. The class name have to be specified in order to pass the objects to a function. This allows the program to create another object of same class or to use the same object that was passed.
Q: The object ________________
A. Can be passed by reference
B. Can be passed by value
C. Can be passed by reference or value
D. Can be passed with reference
Solution: The objects can be passed by reference if required to use the same object. The values can be passed so that the main object remains same and no changes are made to it if the function makes any changes to the values being passed.
Q: If an object is passed by value, _________________
A. Temporary object is used in the function
B. Local object in the function is used
C. Only the data member values are used
D. The values are accessible from the original object
Solution: When an object is called by values, copy constructor is called and object is copied to the local object of the function which is mentioned in the argument list. The values gets copied and are used from the local object. There is no need to access the original object again.
Q: In which type is new memory location will be allocated?
A. Only in pass by reference
B. Only in pass by value
C. Both in pass by reference and value
D. Depends on the code
Solution: The new memory location will be allocated only if the object is passed by value. Reference uses the same memory address and is denoted by another name also. But in pass by value, another object is created and new memory space is allocated for it.
Q: What exactly is passed when an object is passed by reference?
A. The original object name
B. The original object class name
C. The exact address of the object in memory
D. The exact address of data members
Solution: The location of the object, that is, the exact memory location is passed, when the object is passed by reference. The pass by reference is actually a reference to the object that the function uses with another name to the same memory location as the original object uses.
Q: If the object is not to be passed to any function but the values of the object have to be used then?
A. The data members should be passed separately
B. The data members and member functions have to be passed separately
C. The values should be present in other variables
D. The object must be passed
Solution: The data members can be passed separately. There is no need to pass whole object, instead we can use the object to pass only the required values.

You Have Score    /10