[HD Pg 108, Sec. 4.3.2 - assigning-arrays-of-primitives-to-object-variables]

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
enthunoob
Posts: 60
Joined: Thu Apr 15, 2021 12:21 pm
Contact:

[HD Pg 108, Sec. 4.3.2 - assigning-arrays-of-primitives-to-object-variables]

Post by enthunoob »

Very good point made here. Every array is an object. With the example given:

Object[] oa = new int[2][3]; //this is valid.
Object[][] oaa = new int[2][3]; //this will not compile.

It means that the last line would compile if it had a set of braces behind it:
Object[][] oaa = new int[2][3][1]; //this should compile.

Besides that, it also means that the (level of) dimensions do not have to be specified left of the assignment character, right? Cause array or not, it's an object (that on coincidence is an object holding references to other objects). So this would also compile:

Object oa = new int[2][3]; //this should also compile (?)

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 108, Sec. 4.3.2 - assigning-arrays-of-primitives-to-object-variables]

Post by admin »

What happened when you tried it out?
If you like our products and services, please help us by posting your review here.


Post Reply

Who is online

Users browsing this forum: No registered users and 40 guests