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

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

Moderator: admin

Post Reply
timbijnen
Posts: 4
Joined: Fri Oct 03, 2014 5:21 am
Contact:

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

Post by timbijnen »

Code: Select all

public class TestClass{
   static int value = 0; //1
   public static void main(String args[]) //2
   {
      int 2ndArgument = Integer.parseInt(args[2]); //3
      if( true == 2 > 10 ) //4  
      {
         value = -10;
      }
      else{
         value =  2ndArgument;
      }
      for( ; value>0; value--) System.out.println("A"); //5
   }
}
i get that line 3 is causing a compiler error, but isn't it also that line 4 causes one, since the expression always evaluates to false it makes it so that the true part of the if statement is unreachable code. Doesn't change the fact that still line 3 causes a compiler error in the first place but i missed it in the answer description:

== has less precedence than > so true == 2 > 10 is same as true == (2 > 10)

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

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

Post by admin »

Compiler doesn't evaluate value>0 at compile time so it doesn't know that the block is unreachable. Compiler can consider only compile time constant values to evaluate expressions and determine whether a code is unreachable or not.

timbijnen
Posts: 4
Joined: Fri Oct 03, 2014 5:21 am
Contact:

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

Post by timbijnen »

Thanks for your reply! Sounds clear

kabanvau
Posts: 14
Joined: Thu Nov 21, 2019 5:48 am
Contact:

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

Post by kabanvau »

value = -10; will flag an error first! Before line 5. Non-static field 'value' cannot be referenced from a static context.

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

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

Post by admin »

Please read the code carefully. value is, in fact, static. So, there will be no such error.

sijucm
Posts: 8
Joined: Tue Jan 11, 2022 4:41 am

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

Post by sijucm »

How can something be checked if it compiles if the declaration itself does not compile. If //2 does not compile, that means args is not a valid references then how can //3 be checked. I hope these kind of things does not happen in real test because it is confusing. I won't fight the question setter and just mark what she expects me to.

cristibctr
Posts: 5
Joined: Sun Jun 18, 2023 11:03 am
Contact:

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

Post by cristibctr »

admin wrote:
Mon May 24, 2021 8:04 pm
Please read the code carefully. value is, in fact, static. So, there will be no such error.
I'm not sure if this question was updated since this answer was posted but value is, in fact, not static. At least in my test "value" is defined as "var".

That obviously doesn't compile but now you've got an assumption to make in order to find the next line that doesn't compile:
  • Value is static which means that line 5 also compiles so the correct answer list is incorrect
  • Value is not static which means that both value = -10; and value = secondArg; won't compile but these options are not present

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

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

Post by admin »

Could you please mention which question bank / exam code are you using? Because I just checked in the OCA 1z0808 question bank and value is static. The code listing given in the first post of this topic also has it as static.

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

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

Post by admin »

I think I found the issue. A similar question in OCP 11 and 17 question banks with id (enthuware.ocpjp.v17.2.3236) is being incorrectly directed to this discussion, which is what is causing this confusion. This topic is for the OCA question 2.1073 and this question / answer is correct.

The link to the discussion on the OCP question is https://enthuware.com/forum/viewtopic.php?f=2&t=4913

jerry___
Posts: 9
Joined: Tue Nov 26, 2024 2:08 pm
Contact:

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

Post by jerry___ »

The explanation at 5 states:

"value is an instance variable and can only be accessed through a reference. It cannot be accessed directly from a static method because the implicit variable "this" is not available in a static method."

But actually, "value" is not declared properly so we can only guess how it would be declared if it was done properly.

As a solution, var value = 10; could be moved to inside the static method which would make //5 compile just fine.
It could also instead be solved outside the method if declared as: static int value = 10; In that case, //5 would also compile just fine.

In my opinion, any clear question can only ask if X, Y and/ or Z cause problems if X, Y and Z don't depend on each other.

My only question about this is:
Is the ambiguity in this question preparing us for the poorly written exam questions and implicit assumptions just like Oracle writes the actual exams?

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

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

Post by admin »

No, this option is bad and should be fixed.
You will most likely not get a question in the real exam that expects you to make such assumptions. But I cannot say that with 100% certainty because new questions are added in the exam and, after all, they are created by humans and some subjectivity / ambiguity may creep into them inadvertently. If a candidate reports such issue, Oracle fixes it. For example, see this thread where Oracle removed the question after receiving feedback: https://coderanch.com/t/786795/certific ... ort-retook

thanks for the feedback!

shear12345
Posts: 18
Joined: Wed Feb 12, 2025 4:56 pm

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

Post by shear12345 »

There are 2 conflicting lines marked as the same line number (//1):
public class TestClass{
var value = 0; //1
int otherValue = 10; //1
......
}

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

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

Post by admin »

Fixed.
thank you for your feedback!

nkaragulov
Posts: 17
Joined: Mon Sep 16, 2024 1:49 am
Contact:

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

Post by nkaragulov »

shear12345 wrote:
Sat May 24, 2025 3:22 pm
There are 2 conflicting lines marked as the same line number (//1):
public class TestClass{
var value = 0; //1
int otherValue = 10; //1
......
}
I have the same here.
Is there a way I could update my local question bank including already answered questions?

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

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

Post by admin »

Yes, you can just replace your japv8.ets file with enthuware.com/downloads/japv8.ets

nkaragulov
Posts: 17
Joined: Mon Sep 16, 2024 1:49 am
Contact:

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

Post by nkaragulov »

admin wrote:
Sat Jun 07, 2025 5:42 am
Yes, you can just replace your japv8.ets file with enthuware.com/downloads/japv8.ets
Mine is 1z0-830.ets

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

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

Post by admin »

enthuware.com/downloads/1z0-830.ets

nkaragulov
Posts: 17
Joined: Mon Sep 16, 2024 1:49 am
Contact:

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

Post by nkaragulov »

Thank you for help!

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

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

Post by admin »

All question bank download links are available here: https://enthuware.com/help/all-downloads
If there is a critical update to the question bank, ETS Viewer will automatically notify you of the update and can also download the updated question bank. You can also use ETS Viewer's Tools->Check for Question Bank update menu.

Post Reply

Who is online

Users browsing this forum: No registered users and 91 guests