About Question enthuware.ocpjp.v8.2.1462 :
Moderator: admin
-
- Posts: 5
- Joined: Thu Aug 20, 2015 7:32 am
- Contact:
About Question enthuware.ocpjp.v8.2.1462 :
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 }
My answer was:
enum Seasons { SUMMER , WINTER }
where the said correct answer was
private enum Seasons { SUMMER , WINTER }
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1462 :
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.
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.
-
- Posts: 5
- Joined: Thu Aug 20, 2015 7:32 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1462 :
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.
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1462 :
I am sorry but I am not sure what you are saying. In your first post, you wrote:
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.
HTH,
Paul.
To this, I replied to you that the correct answer is indeed enum Seasons { SUMMER , WINTER }.My answer was:
enum Seasons { SUMMER , WINTER }
where the said correct answer was
private 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
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Sun Feb 25, 2018 4:55 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1462 :
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.
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 (32.42 KiB) Viewed 3355 times
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1462 :
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.
HTH,
Paul.
No, there is no rule that says you need to have a public class in a java file.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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 15
- Joined: Tue Feb 25, 2014 3:14 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1462 :
Hi, in your example, you are trying to compile TestClass.java. However, the test questions says the file is Seasons.java.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.HTH,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
Paul.
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.
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1462 :
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.
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.
Who is online
Users browsing this forum: Google [Bot] and 32 guests