Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java

 
Jit Som
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaworski (http://www.jaworski.com/java/certification/) has a question like
In order of MyProgram to be compiled & run, which are true?
Athe MyProgram class must be defined in MyProgram.java
BMyProgram must be declared public
CMyProgram must have a correctly formed main() met.
DMyProgram must import java.lang
and the answre is only B.
is not A also correct?
 
Savithri Devaraj
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not necessarily, because the class could be defined in a package along with other classes, right??
Savithri
 
kusuma janardhana
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in a package,only one class can be public.and that class name is used to name the file.so,...i think 'a' is also correct.what do u say?
 
Maha Ravi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think C should be the only condition.
-Maha
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not C because you don't have to have a main like with applets. It is not D because you don't have to import java.lang.
Now for A and B. I would think 'A' would be true because the question says in order to run and compile MyProgram. If you are running MyProgram then you would have to have it in a file MyProgram.java, correct? When I tried doing this, I got a NoClassDefFound runtime error. As for 'B', I don't think B is correct because a class can be a 'friendly' class and still compile and run. It can't be private or protected, but it can be 'friendly' or public. So I would have said only 'A' is correct.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic