About Question enthuware.ocajp.i.v8.2.1341 :

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

Moderator: admin

Post Reply
oguzcoel
Posts: 1
Joined: Wed Oct 17, 2018 5:30 pm
Contact:

About Question enthuware.ocajp.i.v8.2.1341 :

Post by oguzcoel »

Hello together, I invest hours to identify what's wrong with the code below:


What will be result of attempting to compile this class? import java.util.*;
package test;
public class TestClass{
public OtherClass oc = new OtherClass(); }

class OtherClass{ int value; }

I get the following compilation error:

test.java:3: error: class, interface, or enum expected
package test;

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

Re: About Question enthuware.ocajp.i.v8.2.1341 :

Post by admin »

I tried it just now. It compiles fine. Create a new empty file. Try typing the code manually in that file instead of copy/pasting from elsewhere and then compile from command line.
If you like our products and services, please help us by posting your review here.

Shri Shri
Posts: 5
Joined: Sun May 21, 2017 9:01 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1341 :

Post by Shri Shri »

 public OtherClass oc = new OtherClass();
What is significance of public when we are creating of object ?
If i put public in any of my code, "Illegal modifier for <object name>; only final is permitted"

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

Re: About Question enthuware.ocajp.i.v8.2.1341 :

Post by admin »

Please post the exact code that you are trying to compile.
public modifier is allowed for static and instance fields of a class but not for local variable (i.e variables defined in a method).
If you like our products and services, please help us by posting your review here.

DazedTurtle
Posts: 26
Joined: Wed Oct 02, 2019 1:42 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1341 :

Post by DazedTurtle »

Just wanted to say thanks for this question. Getting the question wrong is going to cement it in my head to read all of the code (and not just the stuff inside the class) a lot better than just being told I have to read the questions carefully.

BaxLi007
Posts: 11
Joined: Wed Jun 26, 2019 12:43 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1341 :

Post by BaxLi007 »

Answer "Class will fail to compile" - logically looks a correct one for the question -@ What will be result of attempting to compile this class?@.
It will fail ... isn't it ?
I understand that it not even attain step of compiling at the checking-before-compile stage, but it anyway "fail-to-compile" result.

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

Re: About Question enthuware.ocajp.i.v8.2.1341 :

Post by admin »

Correct. It will fail to compile, just as the answer says.
If you like our products and services, please help us by posting your review here.

fortesp
Posts: 9
Joined: Mon Dec 14, 2020 8:53 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1341 :

Post by fortesp »

I have an issue with this question.
First, your question is "What will be result of attempting to compile this class?" and there is more than one class in the code snippet. Probably implicitly referring to the public class. Fine.

The compile error, as someone stated before, is not related to the class (or any other class) in the code.
How come the answer is "The class will fail to compile ."? Which class?

The answer should be "None of the above."?

Cheers.

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

Re: About Question enthuware.ocajp.i.v8.2.1341 :

Post by admin »

Updated the question to make it clear.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

matbloswe
Posts: 1
Joined: Wed Mar 08, 2023 7:49 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1341 :

Post by matbloswe »

I still think the question is unclear. I knew the PIC mnemonic so I spotted the wrong order but since it still is two classes I thought that _both_ classes fail to compile, not just TestClass. So I answered "none of the above". Maybe rephrase it as "Compilation fails for a different reason" and don't mention any class names. Fits better with the question also now that it asks "... attempting to compile the following code ..." and not "... attempting to compile this class".

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

Re: About Question enthuware.ocajp.i.v8.2.1341 :

Post by admin »

Fair point. Updated.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: marpiva and 30 guests