Courseiva
Question 504 of 513
Utilizing Java Object-Oriented ApproachmediumMultiple ChoiceObjective-mapped

1Z0-829 Method Overriding Practice Question

Exhibit

Refer to the exhibit.

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello");
    }
}

And the command:

$ javac Main.java
$ java Main

Output:
Hello

Now consider this class in another file:

public class Sub extends Main {
    public static void main(String[] args) {
        System.out.println("World");
    }
}

Compiled and run:

$ java Sub

What is the output?

Refer to the exhibit. Two Java classes are defined as shown. What is the output when the Sub class is executed?

⚠ Common exam trap

Oracle often tests whether candidates understand that an overridden method in a subclass does not automatically execute the superclass version unless explicitly called with super.method(), leading many to mistakenly think the superclass method runs first by default.

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

World

The Sub class overrides the print() method from Super and does not call super.print(). Therefore, when Sub's print() is executed, it only prints "World" without printing "Hello". The output is simply "World".

Answer analysis

Option-by-option breakdown

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

  • HelloWorld

    Why it's wrong here

    Only Sub's main method runs, not both.

  • World

    Why this is correct

    Sub's main method is executed, printing 'World'.

  • Hello

    Why it's wrong here

    Sub's main method does not invoke Main's main; it prints 'World'.

  • No output (compilation error)

    Why it's wrong here

    Both classes compile and run without error.

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 →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on 1Z0-829

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. Refer to the exhibit. What is the result?

hard
  • A.Compilation fails
  • B.Bark Playing
  • C.Runtime exception
  • D.Bark

Why B: The code compiles and runs without error. The object referenced by a1 is a Dog instance. The code first calls the bark() method, which prints 'Bark' (defined in Dog). Then it calls the play() method, which is not overridden in Dog, so it invokes the inherited play() method from Animal, printing 'Playing'. Therefore, the output is 'Bark' followed by 'Playing', which matches option B.

Last reviewed: Jun 30, 2026

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.

Loading comments…

Sign in to join the discussion.

This 1Z0-829 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-829 exam.