Java Practice Quiz 2025 – Complete Test Preparation

Question: 1 / 510

What exception is thrown if you call 'array()' on a buffer not backed by an array?

UnsupportedOperationException

The exception overloaded is UnsupportedOperationException.

Generally excess capacity in the buffer, when calling array function which convert to an array, it will throw UnsupportedOperationException, as there is no array in the ByteBuffer.

The other options, BufferUnderflowException, BufferOverflowException, and ReadOnlyBufferException, are all thrown when there is an issue with the buffer's position, limit, or read/write permissions, respectively. These are not applicable in this scenario as the issue is with the buffer not having an underlying array. Therefore, these options can be ruled out as the correct answer.

Get further explanation with Examzify DeepDiveBeta

BufferUnderflowException

BufferOverflowException

ReadOnlyBufferException

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy