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

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

Moderator: admin

Post Reply
vikavrn90
Posts: 3
Joined: Fri Aug 14, 2020 9:08 pm
Contact:

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

Post by vikavrn90 »

Hi, I don't understand output. ( false, true)
(b1[0] == b2[0]) given false
(b1[1] == b2[1] given false, because b1[1] - false

can somebody please explain this output?


Consider the following code snippet ...
boolean[] b1 = new boolean[2];
boolean[] b2 = {true , false};
System.out.println( "" + (b1[0] == b2[0]) + ", "+ (b1[1] == b2[1]) );
What will it print ?

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

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

Post by admin »

The default values of the elements of a boolean is false. So, b1[0] and b1[1] are false. You are initializing b2[0] to true. Therefore,
(b1[0] == b2[0]) will resolve to false == true. But false is not same as true therefore, the value of the expression false == true is false.

You can work out b1[1] == b2[1] similarly.
If you like our products and services, please help us by posting your review here.

vikavrn90
Posts: 3
Joined: Fri Aug 14, 2020 9:08 pm
Contact:

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

Post by vikavrn90 »

Thank you so much!!!

Post Reply

Who is online

Users browsing this forum: No registered users and 72 guests