Courseiva
Arrays and MethodsmediumMultiple ChoiceObjective-mapped

1Z0-811 Arrays and Methods Practice Question

A team is developing a Java application for an online store. The application has a class 'Inventory' that maintains an array of 'Product' objects. The method 'public void addProduct(Product p)' is intended to add a product to the array. The current implementation uses a fixed-size array of length 100. However, the business has grown, and the array may exceed its capacity. The team needs a solution that allows dynamic resizing without changing the method signature. Which approach should the team take?

⚠ Common exam trap

Many candidates think changing the return type or parameter type is acceptable, but the question explicitly requires keeping the method signature unchanged, so only internal implementation changes are allowed.

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

Modify the method to use an ArrayList<Product> internally and keep the signature.

Using an ArrayList<Product> internally allows the array to dynamically resize as needed, while keeping the method signature unchanged. The method still accepts a Product parameter, but the internal implementation leverages ArrayList's automatic capacity management, eliminating the fixed-size constraint.

Answer analysis

Option-by-option breakdown

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

  • Modify the method to use an ArrayList<Product> internally and keep the signature.

    Why this is correct

    Allows dynamic resizing with same signature.

  • Change the method signature to accept a Product[] array and copy all elements.

    Why it's wrong here

    Changes signature; breaks existing code.

  • Use a Collection<Product> as parameter and convert to array.

    Why it's wrong here

    Changes parameter type; callers must change.

  • Change the return type to boolean and return false if array is full.

    Why it's wrong here

    Changes return type; callers need modification.

About these practice questions

Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.