Question 95 of 481
1Z0-811 Java Basics and Syntax Practice Question
A team decides to use a single Java source file for a small application. Which statement is true about the file structure?
⚠ Common exam trap
Oracle often tests the misconception that a main method is required for compilation, or that multiple public classes are allowed in one file, leading candidates to overlook the strict file-name-to-public-class-name correspondence rule.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
It can contain exactly one public class with the same name as the file.
In Java, when a source file contains a public class, the file name must exactly match the public class name, including case sensitivity. This is a fundamental rule enforced by the Java compiler to ensure proper class loading and package structure. The file can have at most one public top-level class, and that class name determines the file name.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
It must have a main method to compile.
Why it's wrong here
Compilation does not require main.
- ✗
It can contain multiple public classes.
Why it's wrong here
Only one public class per file.
- ✓
It can contain exactly one public class with the same name as the file.
Why this is correct
This is the standard rule.
- ✗
The public class name can differ from the file name.
Why it's wrong here
Must match.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 30, 2026
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.