Q: Which of the following languages has automatic memory management through garbage collection?
-
A
C
-
B
C++
-
C
Java
-
D
All of the above
C
Answer:
C
Explanation:
Java handles memory management automatically through a process called garbage collection. The garbage collector identifies and removes objects that are no longer in use, freeing up memory and reducing the risk of memory leaks. In C and C++, memory management is manual, and programmers are responsible for allocating and deallocating memory using functions like malloc and free in C or new and delete in C++. Failure to manage memory correctly in C and C++ can lead to memory leaks, dangling pointers, or other memory-related issues, making memory management more error-prone compared to Java. Garbage collection simplifies development in Java by allowing developers to focus on their program logic rather than on memory allocation and deallocation, improving safety and stability in larger applications.
Related Topic:
Share Above MCQ