About Question enthuware.ocpjp.v8.2.1462 :

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

Moderator: admin

Post Reply
curiox
Posts: 5
Joined: Thu Aug 20, 2015 7:32 am
Contact:

About Question enthuware.ocpjp.v8.2.1462 :

Post by curiox »

After reading a bit on enums, I checked that my answer is correct, even though the app shows it's incorrect.

My answer was:

enum Seasons { SUMMER , WINTER }

where the said correct answer was

private enum Seasons { SUMMER , WINTER }

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

Re: About Question enthuware.ocpjp.v8.2.1462 :

Post by admin »

I see that enum Seasons { SUMMER , WINTER } is indeed set as the correct answer.
private enum Seasons { SUMMER , WINTER } will not compile and is not set at the correct answer.

Can you please post a screen shot of where it says private enum Seasons { SUMMER , WINTER } is the right answer?
-Paul.
If you like our products and services, please help us by posting your review here.

curiox
Posts: 5
Joined: Thu Aug 20, 2015 7:32 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1462 :

Post by curiox »

It's not that "private enum" is set as correct, I tested in on a vanilla code at ideone.com and it compiled successfully in both cases.

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

Re: About Question enthuware.ocpjp.v8.2.1462 :

Post by admin »

I am sorry but I am not sure what you are saying. In your first post, you wrote:
My answer was:
enum Seasons { SUMMER , WINTER }
where the said correct answer was
private enum Seasons { SUMMER , WINTER }
To this, I replied to you that the correct answer is indeed enum Seasons { SUMMER , WINTER }.
private enum Seasons { SUMMER , WINTER } is not a correct answer and is not shown as correct in the simulator either.

For the purpose of the exam, we only rely on command line javac tool and if you try to compile the following code using javac, you will get an error message.

Code: Select all

private enum Seasons{ SUMMER, WINTER }

class TestClass {
  public TestClass(){ }

}

C:\temp>javac TestClass.java
TestClass.java:1: error: modifier private not allowed here
private enum Seasons{ SUMMER, WINTER }
        ^
1 error
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

abelkin
Posts: 1
Joined: Sun Feb 25, 2018 4:55 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1462 :

Post by abelkin »

Hello!

Well, I don't agree with this question anyway, because in one case it's not about Java at all, it's about your editor.
Look at this picture. You see the light-yellow line above the constructor of the TestClass. Why do we know that you want us to telepathically understand that this should be above the first line of the code?
This code with the private enum does not compile, but it doesn't depend with the Enum rules in your explanation. It does not compile because of no public classes in the java-file, but it only works so when this line is above the first line in the code.
So, to be correct you should improve your explanation of where you want us to write this source of line.
Attachments
Capture.PNG
Capture.PNG (32.42 KiB) Viewed 3354 times

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

Re: About Question enthuware.ocpjp.v8.2.1462 :

Post by admin »

Sorry but I am not sure why you think that the code that you are asked to write above the code that is already given may appear anywhere else. It is quite clear from the given question that these are the contents of Seasons.java class and the code that you are expected to write goes right above the definition of TestClass.
It does not compile because of no public classes in the java-file, but it only works so when this line is above the first line in the code.
No, there is no rule that says you need to have a public class in a java file.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

dvc1190
Posts: 15
Joined: Tue Feb 25, 2014 3:14 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1462 :

Post by dvc1190 »

admin wrote:
Thu Jun 09, 2016 2:32 pm

For the purpose of the exam, we only rely on command line javac tool and if you try to compile the following code using javac, you will get an error message.

Code: Select all

private enum Seasons{ SUMMER, WINTER }

class TestClass {
  public TestClass(){ }

}

C:\temp>javac TestClass.java
TestClass.java:1: error: modifier private not allowed here
private enum Seasons{ SUMMER, WINTER }
        ^
1 error
HTH,
Paul.
Hi, in your example, you are trying to compile TestClass.java. However, the test questions says the file is Seasons.java.

I'll also point out that the explanation given for the correct answer doesn't tell you why the "private" modifier is not allowed for the Seasons enum.

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

Re: About Question enthuware.ocpjp.v8.2.1462 :

Post by admin »

Yes, the file name should have been Seasons.java but that wouldn't have made any difference. It still would not have compiled and would have given the same error message.
private modifier is not allowed for top level non-nested type definitions. This is a rule of Java language.
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 45 guests