124k views
0 votes
How do you declare an array of object references?

a) ClassName[] arrayName = new ClassName[];
b) ClassName[] arrayName = new ClassName[size];
c) ClassName[] arrayName = new ClassName();
d) ClassName[] arrayName;

User Enterprize
by
7.9k points

1 Answer

2 votes

Final answer:

The correct way to declare an array of object references in Java is with the syntax ClassName[] arrayName = new ClassName[size].

Step-by-step explanation:

The correct way to declare an array of object references in Java is option b) ClassName[] arrayName = new ClassName[size];

For example, if you have a class named Student, and you want to create an array of object references to store multiple student objects, you would declare it like this:

Student[] studentArray = new Student[5];

This creates an array of object references to hold 5 Student objects. Each element in the array can store a reference to a Student object.

User Adam Lukaszczyk
by
8.2k points