Test Series - oops

Test Number 27/78

Q: What does memory allocation for objects mean?
A. Actual creation and memory allocation for object members
B. Creation of member functions
C. Creation of data members for a class
D. Actual creation and data declaration for object members
Solution: The memory allocated for the object members indicates actual creation of the object members. This is known as memory allocation for object.
Q: Where is the memory allocated for the objects?
A. HDD
B. Cache
C. RAM
D. ROM
Solution: The memory for the objects or any other data is allocated in RAM initially. This is while we run a program all the memory allocation takes place in some RAM segments. Arrays in heap and local members in stack etc.
Q: When is the memory allocated for an object?
A. At declaration of object
B. At compile time
C. When object constructor is called
D. When object is initialized to another object
Solution: The object memory allocation takes place when the object constructor is called. Declaration of an object doesn’t mean that memory is allocated for its members. If object is initialized with another object, it may just get a reference to the previously created object.
Q: Using new is type safe as _______________________
A. It require to be specified with type of data
B. It doesn’t require to be specified with type of data
C. It requires the name of data
D. It allocated memory for the data
Solution: The new is type safe because we don’t have to specify the type of data that have to be allocated with memory. We can directly use it with data name. Name of the data doesn’t matter though for type of memory allocation though.
Q: Which of the following function can be used for dynamic memory allocation of objects?
A. malloc()
B. calloc()
C. create()
D. malloc() and calloc()
Solution: The malloc() function can be used to allocate dynamic memory for objects. Function calloc() can also be use. These functions differ in the way they allocate memory for objects.
Q: Which keyword among the following can be used to declare an array of objects in java?
A. new
B. create
C. allocate
D. arr
Solution: The keyword new can be used to declare an array of objects in java. The syntax must be specified with an object pointer which is assigned with a memory space containing the required number of object space. Even initialization can be done directly.
Q: When is the memory allocated for an object gets free?
A. At termination of program
B. When object goes out of scope
C. When main function ends
D. When system restarts
Solution: Whenever an object goes out of scope, the deletion of allocation memory takes place. Actually the data is not deleted, instead the memory space is flagged to be free for further use. Hence whenever an object goes out of scope the object members become useless and hence memory is set free.
Q: Which function is called whenever an object goes out of scope?
A. Destructor function
B. Constructor function
C. Delete function
D. Free function
Solution: The destructor function of the class is called whenever an object goes out of scope. This is because the destructor set all the resources, acquired by the object, free. This is an implicit work of compiler.
Q: Which operator can be used to check the size of an object?
A. sizeof(objectName)
B. size(objectName)
C. sizeofobject(objectName)
D. sizedobject(objectName)
Solution: The sizeof operator is used to get the size of an already created object. This operator must constail keyword sizeof(objectName). The output will give the number of bytes acquired by a single object of some class.
Q: The memory allocated for an object ____________________
A. Can be only dynamic
B. Can be only static
C. Can be static or dynamic
D. Can’t be done using dynamic functions
Solution: The memory allocation for an object can be static or dynamic. The static memory allocation is when an object is declared directly without using any function usually. And dynamic allocation is when we use some dynamic allocation function to allocate memory for data member of an object.

You Have Score    /10