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 ?
About Question enthuware.ocpjp.i.v11.2.1262 :
Moderator: admin
-
- Posts: 3
- Joined: Fri Aug 14, 2020 9:08 pm
- Contact:
-
- Site Admin
- Posts: 10045
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.1262 :
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.
(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.
-
- Posts: 3
- Joined: Fri Aug 14, 2020 9:08 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.1262 :
Thank you so much!!!
Who is online
Users browsing this forum: No registered users and 72 guests