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
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?
Enthuware Software Support
posted 5 months ago
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.