[HD Pg 0, Sec. 4.3.4 - relationship-between-java-source-file-name-and-class-name]
Posted: Mon Mar 02, 2020 10:17 am
Hi all.
Reading "4.3.4 Relationship between Java source file name and class name":
And on the contrary, when I place one or more private/protected classes in java file, I get compiler error " modifier protected not allowed here". Is this a misprint in the book or I miss something again?
Thank you.
Reading "4.3.4 Relationship between Java source file name and class name":
I tried to place several public classes in a single java file and compiler did`t produce any errors (I use command line and Java SE v11.0.6). More over, I could successfully run the application. The question is: do I miss something or there is an error in the "OCP Oracle Certified Professional Java SE 11 Programmer I Exam Fundamentals 1Z0-815: Study guide for passing the OCP Java 11 Developer Certification Part 1 Exam 1Z0-815" book?Q. Does that mean I cannot have multiple classes in a single file?
A. No, you certainly can have multiple classes in a single file. But only one of
them can be public and the name of that public class must be the same as the
name of the file. It is okay even if there is no public class in a file.
And on the contrary, when I place one or more private/protected classes in java file, I get compiler error " modifier protected not allowed here". Is this a misprint in the book or I miss something again?
Thank you.