levo

Objects, Classes and Data Structures

Arrays of objects

  • 3 things to know
  • AS Unit 1
Start revising · £5/month

Overview

Declaring an array whose elements are objects, why every element starts empty, creating each object before it is used, and the error raised by reaching through an element that holds nothing.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

Describe how the object with the highest value of an attribute is found in an array of objects.

Key term

A library program declares an array of 200 Book references but currently holds only 40 books. What is the cost of that decision?

Key term

What has to be done to an element of an array of objects before it can be used?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What does the statement Student[] group = new Student[3]; create?

    Model answer

    The statement creates an array able to hold three Student references, and no Student object exists yet because every element starts as null.

  2. 2

    A program executes Student[] group = new Student[3]; and then System.out.println(group[0]);. What is printed?

    Model answer

    The statement prints null, because creating the array reserves three reference slots and sets each of them to refer to no object at all.

  3. 3

    What has to be done to an element of an array of objects before it can be used?

    Model answer

    Each element must be given an object of its own, as in group[0] = new Student("Aoife");, before any method can be called through that element.

  4. 4

    A program executes Student[] group = new Student[3]; and then group[0].getName();. What happens?

    Model answer

    The program stops with a null pointer exception at run time, because element 0 still refers to no object and there is nothing on which getName could be called.

  5. 5

    What does each element of an array of objects actually store?

    Model answer

    Each element stores a reference to an object held elsewhere in memory rather than the object itself.

  6. 6

    Contrast what is stored in an array of integers with what is stored in an array of objects.

    Model answer

    An array of a simple type holds the values themselves inside the array, while an array of objects holds references and the objects sit separately in memory.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A null is the of one.
absencepresencetype

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Objects, Classes and Data Structures, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.