Courseiva
Arrays and MethodshardMultiple ChoiceObjective-mapped

1Z0-811 Arrays and Methods Practice Question

Which of the following correctly describes the effect of the method call 'Arrays.sort(myArray)' on an array of objects that do not implement Comparable?

⚠ Common exam trap

Test-takers frequently assume the code will not compile (Option A) because they think `Comparable` is required at compile time, but the requirement is enforced at runtime via a cast, leading to a `ClassCastException`.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

A ClassCastException is thrown at runtime.

When `Arrays.sort(myArray)` is called on an array of objects that do not implement the `Comparable` interface, the method attempts to cast elements to `Comparable` to compare them. Since the objects do not implement `Comparable`, a `ClassCastException` is thrown at runtime. The `Arrays.sort(Object[])` method requires that all elements implement `Comparable`; otherwise, it cannot determine a natural ordering.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The code does not compile because Arrays.sort requires a Comparator.

    Why it's wrong here

    Arrays.sort(Object[]) compiles; exception at runtime.

  • A ClassCastException is thrown at runtime.

    Why this is correct

    Elements must implement Comparable.

  • The array is sorted using the natural order of the elements.

    Why it's wrong here

    Natural order requires Comparable implementation.

  • The array is sorted using the order defined by the elements' equals method.

    Why it's wrong here

    Sorting uses compareTo, not equals.

About these practice questions

One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.