← Quiz: Java Introduction: all 10 questions
Quiz: Java Introduction · Question 8 of 10
A file named Main.java contains public class Hello { ... }. What happens when you run javac Main.java?
A file named Main.java contains public class Hello { ... }. What happens when you run javac Main.java?
- A.Compile error: a public class must be in a file with the same name (Hello.java)
- B.It compiles and creates Main.class
- C.It compiles but fails when you run it
- D.javac renames the file automatically
Answer & explanation
Correct answer: Compile error: a public class must be in a file with the same name (Hello.java)
The name of a public class and its file must match exactly, including capital letters.
Can you get the rest right without peeking?
Take the timed Quiz: Java Introduction quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →