About Question enthuware.ocajp.i.v7.2.1413 :

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

Moderator: admin

Post Reply
gparLondon
Posts: 63
Joined: Fri Oct 31, 2014 6:31 pm
Contact:

About Question enthuware.ocajp.i.v7.2.1413 :

Post by gparLondon »

How come the compiler knows about the value of the counter, before the program has been run? or how will it evaluates if condition before the program being executed?

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

Re: About Question enthuware.ocajp.i.v7.2.1413 :

Post by admin »

It doesn't know the value of counter but it knows that there is an if part and there is an else part. The if part contains break and the else part contains continue, so no matter what is the value of counter, nothing after the if/else statement can be executed.
If you like our products and services, please help us by posting your review here.

Vermeulen
Posts: 12
Joined: Wed Jul 15, 2015 4:05 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1413 :

Post by Vermeulen »

Is it really one of the OCA exam objectives to know when the compiler can identify unreachable code?

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

Re: About Question enthuware.ocajp.i.v7.2.1413 :

Post by admin »

Yes, you may get questions that require you know when the code will not compile because of this reason.
If you like our products and services, please help us by posting your review here.

AnneLy
Posts: 1
Joined: Sun Oct 18, 2015 12:53 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1413 :

Post by AnneLy »

in the syntax (value<4) in the question does it mean that the program is trying to access the whole value of the array & check if its less than 4 ?

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

Re: About Question enthuware.ocajp.i.v7.2.1413 :

Post by admin »

AnneLy wrote:in the syntax (value<4) in the question does it mean that the program is trying to access the whole value of the array & check if its less than 4 ?
No, the code is inside the forEach loop i.e. forEach(int value : arr){ ... }. So value > 4 compares a value in the array with 4.
If you like our products and services, please help us by posting your review here.

erickdeoliveiraleal
Posts: 1
Joined: Mon Jan 29, 2018 1:47 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1413 :

Post by erickdeoliveiraleal »

and remember break and continue only works for loops.

baichen7788
Posts: 23
Joined: Fri Mar 26, 2021 7:25 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1413 :

Post by baichen7788 »

that makes no sense.
the following run well , but the code below continue is also unreachable,which is never executed.


int[] arr = {1,2,3,4,5};
for (int value :arr
) {
if (value ==0){
System.out.println("0000");
}else {
continue;
}
if (true){
System.out.println(true);
}
System.out.println("last line");
}

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

Re: About Question enthuware.ocajp.i.v7.2.1413 :

Post by admin »

if(true) is an exception to the rule. See this (read the part towards the end about conditional compilation): https://docs.oracle.com/javase/specs/jl ... #jls-14.21
This point is covered in other questions.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests