This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

lack of public class in a file

 
Jason Attin
Ranch Hand
Posts: 232
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, here is a rather confusing question from Glenn, Mitchell. OCAJP Oracle Certified Associate Java SE 8 Programmer Practice Exams (Kindle Locations 9041-9049). Enthuware. Kindle Edition.

The options below contain the complete contents of a file. Which of these options can be run with the following command line once compiled? java main
Select 1 option
A.
B.
C.
D.

I went for option D, not entirely sure why, it seemed more correct and I got that right. But then, when I read the explanation I thought about it again and realized that it doesn't sound so right after all (the explanation doesn't say much anyway so I didn't copy that over). What doesn't convince me is the fact hat there isn't any public class in D and I always thought that a file to compile HAD to have a public class which matched the name of the file, but that's not happening in D. Any idea?
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3819
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not necessary for a java file to have a public class. The requirement is that if a class (or enum) is public then that class (or enum) must be defined in a file by the same name and that there can be only one public class (or enum) in one file.

This explanation has now been added to the question.

HTH,
Paul.
 
Jason Attin
Ranch Hand
Posts: 232
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK I see, thanks for clarifying that
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic