About Question enthuware.ocpjp.i.v11.2.3230 :

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

Moderator: admin

Post Reply
zunayeed
Posts: 10
Joined: Fri Jun 28, 2019 10:58 am
Contact:

About Question enthuware.ocpjp.i.v11.2.3230 :

Post by zunayeed »

we know that, var is not valid for array declaration. Can you please explain how come does this work ?
var ia = new int[][]{ {1, 2}, null };

thanks

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

Re: About Question enthuware.ocpjp.i.v11.2.3230 :

Post by admin »

Where did you read that var is not valid for array declaration??
If you like our products and services, please help us by posting your review here.

zunayeed
Posts: 10
Joined: Fri Jun 28, 2019 10:58 am
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3230 :

Post by zunayeed »

Not allowed with array initializer (an array initializer still needs an explicit target type):

public static void main(String[] args) {
var arr = {1, 2, 3};
}
source: http://java.boot.by/ocpjd11-upgrade-gui ... .html#c7s1
Can you please explain why I get this information wrong ?
thank you

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

Re: About Question enthuware.ocpjp.i.v11.2.3230 :

Post by admin »

Well, there is a difference between the two. The type is specified explicitly in new int[][]{ {1, 2}, null }; , so compiler can determine the type of the variable. But not in case of {1, 2, 3};. How will the compiler know what type to use for var? It could be short or byte array also.

Also, you might want to check with the author of that article and get his opinion.
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 35 guests