Test Series - oops

Test Number 28/78

Q: If an object is declared in a user defined function __________________
A. Its memory is allocated in stack
B. Its memory is allocated in heap
C. Its memory is allocated in HDD
D. Its memory is allocated in cache
Solution: The memory for any data or object that are used in a user defined function are always allocated in the stack. This is to ensure that the object is destroyed as soon as the function is returned. Also this ensures that the correct memory allocation and destruction is performed.
Q: In java, ____________________ takes care of managing memory for objects dynamically.
A. Free collector
B. Dust collector
C. Memory manager
D. Garbage collector
Solution: The garbage collector in java takes care of the memory allocations and their deletions dynamically. When an object is no more required then the garbage collector deletes the object and free up all the resources that were held by that object.
Q: Which operator can be used to free the memory allocated for an object in C++?
A. Free()
B. delete
C. Unallocate
D. Collect
Solution: 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++.
Q: 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 types
Solution: 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.
Q: 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 data
Solution: 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.
Q: What is the type of elements of array of objects?
A. Class
B. Void
C. String
D. Null
Solution: 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.
Q: 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 constructor
Solution: 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.
Q: 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 data
Solution: 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.
Q: 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 constructors
Solution: 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.
Q: How the objects of array can be denoted?
A. Indices
B. Name
C. Random numbers
D. Alphabets
Solution: 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.

You Have Score    /10