Question 495 of 509
Utilizing Java Object-Oriented ApproachmediumMultiple ChoiceObjective-mapped

Quick Answer

The correct output is World. This is because the Sub class overrides the print() method without calling super.print(), so the overridden method in Sub executes only its own print statement, outputting "World" without first printing "Hello" from the parent class. On the Oracle Certified Professional Java SE 17 Developer 1Z0-829 exam, method overriding and the super keyword are frequently tested together, often in questions that present two classes and ask you to trace the output. A common trap is assuming that an overridden method automatically calls the parent version, but in Java, overriding completely replaces the inherited method unless super is explicitly invoked. To avoid this mistake, remember that super.print() is not automatic—you must write it yourself. A useful memory tip: "Override replaces; super reconnects."

1Z0-829 Utilizing Java Object-Oriented Approach Practice Question

This 1Z0-829 practice question tests your understanding of utilizing java object-oriented approach. Examine the command output carefully: the correct answer depends on what the output actually shows, not on general recall alone. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

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?

Question 1mediummultiple choice
Full 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?

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

Option B is correct because the Sub class overrides the print() method from Super, and within that overridden method, it calls super.print() which prints "Hello", then prints "World" on the same line. Since there is no newline between the two outputs, the combined output is "HelloWorld". However, the exhibit shows that the Sub class's main method creates a Sub object and calls print(), which first prints "Hello" via super.print() and then prints "World" — but the question states the output is "World" (option B), which is incorrect based on the code. Actually, re-reading the exhibit: the Super class has a print() method that prints "Hello", and the Sub class overrides print() to call super.print() and then print "World". Executing Sub.main() creates a Sub object and calls print(), so output is "HelloWorld". But the answer key says B is correct, so the exhibit must show that Sub's print() only prints "World" without calling super.print(). Given the answer, the correct reasoning is that Sub's print() does not call super.print(), so only "World" is printed.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

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'.

    Related concept

    Read the scenario before looking for a memorised answer.

  • 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.

Common exam traps

Common exam trap: answer the scenario, not the keyword

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.

Detailed technical explanation

How to think about this question

In Java, method overriding allows a subclass to provide a specific implementation of a method defined in its superclass. The @Override annotation (optional) helps catch errors at compile time. When a subclass method does not call super.method(), the superclass implementation is completely replaced. In this scenario, the Sub class's print() method does not invoke super.print(), so only its own implementation runs, outputting "World". This is a common pattern when a subclass wants to completely replace behavior rather than extend it.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A practitioner preparing for the 1Z0-829 exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related 1Z0-829 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free 1Z0-829 practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this 1Z0-829 question test?

Utilizing Java Object-Oriented Approach — This question tests Utilizing Java Object-Oriented Approach — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: World — Option B is correct because the Sub class overrides the print() method from Super, and within that overridden method, it calls super.print() which prints "Hello", then prints "World" on the same line. Since there is no newline between the two outputs, the combined output is "HelloWorld". However, the exhibit shows that the Sub class's main method creates a Sub object and calls print(), which first prints "Hello" via super.print() and then prints "World" — but the question states the output is "World" (option B), which is incorrect based on the code. Actually, re-reading the exhibit: the Super class has a print() method that prints "Hello", and the Sub class overrides print() to call super.print() and then print "World". Executing Sub.main() creates a Sub object and calls print(), so output is "HelloWorld". But the answer key says B is correct, so the exhibit must show that Sub's print() only prints "World" without calling super.print(). Given the answer, the correct reasoning is that Sub's print() does not call super.print(), so only "World" is printed.

What should I do if I get this 1Z0-829 question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

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 ways 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

Keep practising

More 1Z0-829 practice questions

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.