Courseiva
Java Basics and SyntaxhardMultiple ChoiceObjective-mapped

1Z0-811 Java Basics and Syntax Practice Question

Exhibit

public class InitOrder {
    static { System.out.print("A "); }
    { System.out.print("B "); }
    public InitOrder() { System.out.print("C "); }
    public static void main(String[] args) {
        new InitOrder();
    }
}

Given the following code:

class A {

A() { System.out.print("A "); }

}
class B extends A {

B() { System.out.print("B "); }

}
class C extends B {

C() { System.out.print("C"); }

public static void main(String[] args) {

new C();

}
}

What is the output when running the main method?

⚠ Common exam trap

Oracle often tests the order of constructor execution in inheritance, and the trap here is that candidates mistakenly think constructors execute from child to parent (like destructors in C++) or confuse the output order with method overriding behavior, leading them to choose 'C B A' or 'B A C'.

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

A B C

In Java, when an object of a subclass is created, constructors are executed from the topmost superclass down to the subclass. Assuming the exhibit shows class C extends B extends A, with each constructor printing its class name, the output will be A B C.

Answer analysis

Option-by-option breakdown

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

  • B A C

    Why it's wrong here

    Static block runs before instance creation.

  • A B C

    Why this is correct

    Static init block, then instance init block, then constructor.

  • A C B

    Why it's wrong here

    Instance init block runs before constructor body.

  • C B A

    Why it's wrong here

    Static block runs first, then instance init, then constructor.

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.