error: class TestClass is public, should be declared in a file named TestClass.java
About Question enthuware.ocajp.i.v7.2.1263 :
Moderator: admin
-
- Posts: 5
- Joined: Wed May 01, 2013 5:46 am
- Contact:
About Question enthuware.ocajp.i.v7.2.1263 :
The explanation for this question assumes that the code will exist in a file named "TestClass.java". If this is not true, the code will fail to compile with an additional error:
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1263 :
Anything that is not specified in the question should be assumed to be good. This is a standard practice in the real exam as well. It is not possible to specify every possible thing. For example, the question doesn't mention that that the resulting class file is in classpath either, or that jdk is installed.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 5
- Joined: Thu Nov 07, 2013 6:06 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1263 :
What about the semicolon after the main? I've made some tests and it seems like I can put semicolons after every single methods and classes.
So.. are the semicolons optional after the methods and classes?
So.. are the semicolons optional after the methods and classes?
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1263 :
Semi-colon after methods/classes is a no-op instruction. It has no use but is not an error either.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Sat Apr 12, 2014 8:59 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1263 :
If the file will not compile then how come the output is:The file will not compile because TC is a top level class and private is not a valid access modifier for a top level class. private can be applied to an inner class.
"Only "TestClass created" will be printed."
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1263 :
Not sure what you mean. The correct option is "None of the above" exactly for that reason as explained in the explanation.
If you like our products and services, please help us by posting your review here.
-
- Posts: 6
- Joined: Thu May 08, 2014 12:13 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1263 :
OK. But what about public and protected ? They can be applied to top level class unlike private ?
Thanks in adv.
Thanks in adv.
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1263 :
What did you observe when you tried it out?
If you like our products and services, please help us by posting your review here.
-
- Posts: 36
- Joined: Tue May 06, 2014 8:30 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1263 :
Just a thought but I think it would be helpful to include within the explanation that only public and default access modifiers are available to be used with top level class.
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1263 :
Good suggestion. Added.
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Fri Apr 24, 2015 9:04 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1263 :
Is it correct that this code doesn't compile because it extends an interface rather then implement it?
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1263 :
No, where do you see an interface here? Please go through the explanation. It explains why it doesn't compile.lucvandewall wrote:Is it correct that this code doesn't compile because it extends an interface rather then implement it?
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 40 guests