Multiple choice technology programming languages

A single source file can contain multiple class definitions, each having any access modifier.

  1. True

  2. False

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

In Java, a source file can contain multiple classes, but only one can be public. The public class name must match the filename. Non-public classes can have any access modifier, making the original statement false.

AI explanation

In Java, a single .java source file can contain multiple class definitions, but only one of them may be declared 'public' (and it must match the filename); the rest must be package-private (no modifier) or otherwise restricted — they cannot each carry 'any' access modifier such as public. Java restricts top-level classes to only 'public' or default (package-private) visibility anyway — 'private' and 'protected' aren't even legal for top-level classes. So the statement as given is False.