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.

51.

In java, ____________________ takes care of managing memory for objects dynamically.(a) Free collector(b) Dust collector(c) Memory manager(d) Garbage collectorI had been asked this question in final exam.Asked question is from Memory Allocation of Object topic in chapter Object of Object Oriented Programming

Answer»

The CORRECT option is (d) Garbage collector

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

52.

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 cacheThe question was posed to me in a national level competition.I'm obligated to ask this question of Memory Allocation of Object in section Object of Object Oriented Programming

Answer»

The correct option is (a) Its memory is allocated in stack

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

53.

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 functionsI got this question by my college director while I was bunking the class.This intriguing question comes from Memory Allocation of Object in section Object of Object Oriented Programming

Answer»

Correct CHOICE is (C) Can be static or dynamic

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

54.

Which operator can be used to check the size of an object?(a) sizeof(objectName)(b) size(objectName)(c) sizeofobject(objectName)(d) sizedobject(objectName)The question was posed to me in final exam.The doubt is from Memory Allocation of Object in portion Object of Object Oriented Programming

Answer»

Correct answer is (a) SIZEOF(objectName)

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

55.

Which function is called whenever an object goes out of scope?(a) Destructor function(b) Constructor function(c) Delete function(d) Free functionI have been asked this question by my college professor while I was bunking the class.Question is taken from Memory Allocation of Object in portion Object of Object Oriented Programming

Answer» CORRECT choice is (a) Destructor function

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

Which among the following keyword can be used to free the allocated memory for an object?(a) delete(b) free(c) either delete or free(d) only deleteI got this question by my school teacher while I was bunking the class.Origin of the question is Memory Allocation of Object in chapter Object of Object Oriented Programming

Answer»

Right choice is (c) EITHER delete or free

For explanation: The memory allocated for an OBJECT is USUALLY automatically made free. But if explicitly memory has to be made free then we can USE either free or delete keywords depending on programming LANGUAGES.

57.

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 restartsI have been asked this question during an interview for a job.Enquiry is from Memory Allocation of Object in portion Object of Object Oriented Programming

Answer»

The correct CHOICE is (b) When object GOES out of scope

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

58.

Which keyword among the following can be used to declare an array of objects in java?(a) new(b) create(c) allocate(d) arrThe question was posed to me by my school principal while I was bunking the class.My question is from Memory Allocation of Object in division Object of Object Oriented Programming

Answer» CORRECT choice is (a) new

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

Which of the following function can be used for dynamic memory allocation of objects?(a) malloc()(b) calloc()(c) create()(d) malloc() and calloc()I have been asked this question during an internship interview.I need to ask this question from Memory Allocation of Object in division Object of Object Oriented Programming

Answer»

The correct CHOICE is (d) malloc() and calloc()

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

60.

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 dataThis question was addressed to me in a national level competition.My doubt is from Memory Allocation of Object topic in division Object of Object Oriented Programming

Answer»

Correct option is (b) It doesn’t REQUIRE to be specified with type of data

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

61.

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 objectThe question was posed to me in an interview for internship.My doubt stems from Memory Allocation of Object topic in division Object of Object Oriented Programming

Answer» RIGHT answer is (C) When object constructor is called

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

Where is the memory allocated for the objects?(a) HDD(b) Cache(c) RAM(d) ROMThis question was addressed to me in unit test.The question is from Memory Allocation of Object topic in chapter Object of Object Oriented Programming

Answer»

The CORRECT ANSWER is (c) RAM

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

63.

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 membersThis question was posed to me in quiz.Question is taken from Memory Allocation of Object topic in portion Object of Object Oriented Programming

Answer» CORRECT CHOICE is (a) Actual creation and memory ALLOCATION for object members

Explanation: The memory ALLOCATED for the object members indicates actual creation of the object members. This is KNOWN as memory allocation for object.
64.

Can reference to an object be returned from a method?(a) Yes, always possible(b) Yes, but not always(c) No, never possible(d) No, Not possible because referred element would be destroyedThe question was asked during an internship interview.My question comes from Object Reference topic in division Object of Object Oriented Programming

Answer»

The correct option is (b) Yes, but not always

Easy explanation - This is possible but not always, since the reference being RETURNED may get DESTROYED with the return of method. This is an UNDESIRABLE condition, HENCE it is not always possible to return REFERENCES. But it is always possible if the referred element is not local to the method.

65.

Invoking a method on a particular object is ____________ sending a message to that object.(a) Different from(b) Same as(c) Somewhat similar(d) Part ofThis question was posed to me in an online interview.This intriguing question comes from Object Reference topic in portion Object of Object Oriented Programming

Answer»

Right CHOICE is (b) Same as

To explain: The methods invoked on a particular OBJECT is same as SENDING a message with same VALUES to that object. Message would CONTAIN values in a particular format that can be used by the object. And calling a method would be just another way to do the same task.