🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Compile error: a public class must be in a file with the same name (Hello.java)
  2. B.It compiles and creates Main.class
  3. C.It compiles but fails when you run it
  4. 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 →