Courseiva
Java Basics and SyntaxhardMultiple ChoiceObjective-mapped

1Z0-811 Java Basics and Syntax Practice Question

Exhibit

Refer to the exhibit.

javac Test.java
Test.java:3: error: class Test is public, should be declared in a file named Test.java
public class Test {
       ^
1 error

What likely caused this compilation error?

⚠ Common exam trap

Oracle often tests the rule that the public class name must match the filename, and candidates mistakenly think the main method or file extension is the cause of the error.

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

The filename does not match the public class name

The compilation error occurs because Java requires that the public class name exactly matches the filename (including case) when the class is declared as public. If the filename is different from the public class name, the compiler will fail with an error indicating the class name is incorrect or cannot be found.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The main method is missing

    Why it's wrong here

    Error is about class-file name mismatch, not about main method.

  • The file is saved with a .txt extension instead of .java

    Why it's wrong here

    The error message mentions .java, so extension is .java.

  • The filename does not match the public class name

    Why this is correct

    Correct: public class Test must be in Test.java file.

  • The class name contains a typo

    Why it's wrong here

    Error message shows class Test is public, so name matches typical file name.

About these practice questions

One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.