Java MCQ: Which exception is thrown when Java is out of memory?
a) MemoryError
b) OutOfMemoryError
c) NullPointerException
d) IOException
Answer:
b) OutOfMemoryError
Explanation:
When the Java Virtual Machine (JVM) runs out of memory, it throws an OutOfMemoryError
. This error indicates that the JVM cannot allocate an object because it is out of memory and no more memory can be made available by the garbage collector.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html