About Question enthuware.ocajp.i.v8.2.1341 :
Moderator: admin
-
- Posts: 1
- Joined: Wed Oct 17, 2018 5:30 pm
- Contact:
About Question enthuware.ocajp.i.v8.2.1341 :
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;
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;
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1341 :
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.
-
- Posts: 5
- Joined: Sun May 21, 2017 9:01 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1341 :
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"
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"
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1341 :
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).
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.
-
- Posts: 26
- Joined: Wed Oct 02, 2019 1:42 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1341 :
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.
-
- Posts: 11
- Joined: Wed Jun 26, 2019 12:43 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1341 :
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.
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.
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1341 :
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.
-
- Posts: 9
- Joined: Mon Dec 14, 2020 8:53 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1341 :
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.
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.
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1341 :
Updated the question to make it clear.
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Wed Mar 08, 2023 7:49 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1341 :
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".
-
- Site Admin
- Posts: 10102
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1341 :
Fair point. Updated.
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 63 guests