Multiple choice technology programming languages

Are you allowed to have more than one top-level(non-inner) class definition per source file?

  1. True

  2. False

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Java allows multiple top-level (non-inner) class definitions in a single source file. However, only one class can be declared public, and if present, that public class name must match the filename. Other non-public classes can coexist in the same file.

AI explanation

True — a single Java source file may contain more than one top-level (non-inner) class definition; the restriction is only that at most one of them may be declared public, and if there is a public one, the file name must match that public class's name. Any additional top-level classes in the same file must be package-private (no access modifier). So multiple top-level classes are perfectly legal, just with that one naming/visibility constraint, making 'True' the correct answer.