SaveMyCert
Log in
5 of 5 free questions left today·for 30 a day
1Z0-831 · Domain 3

Applying Object-Oriented Principles in Java Programs practice questions

Applying Object-Oriented Principles in Java Programs is worth 18% of the 1Z0-831 exam — the heaviest of the 10 domains. Objects and their life cycle, classes and records, overloading, scope and immutability, inheritance with abstract and sealed types, interfaces and enums. Oracle publishes no domain weights; weight approximates the objective share, with a floor for every section. 6 fully worked examples are further down this page, answers included.

Exam weight
18%
the heaviest of the 10 domains
Questions
175
across 7 topics
Free, no account
5/day
a free account allows 30 a day
Explanations
Every option
right and wrong

Build a practice session

5 free questions left today.

Domains

How many?

Mode

Ready when you are

10 fresh questions drawn across 1 of 10 domains, in Learn mode.

Focused review

Every question you answer incorrectly, and every question you flag while practising, is saved here automatically. Finish a session and you can come back to re-drill just those.

6 sample Applying Object-Oriented Principles in Java Programs questions, fully explained

Questions from the 1Z0-831 bank mapped to domain 3, with the answer key and the reasoning behind every option. None of them repeat the examples on the main 1Z0-831 practice page.

Question 1Applying Object-Oriented Principles in Java Programs

Given:class Counter { static int total; int mine; Counter() { total++; mine++; } } public class Main { public static void main(String[] args) { new Counter(); new Counter(); Counter c = new Counter(); System.out.println(Counter.total + " " + c.mine); } }What is the result?

Choose one.

  • a
    1 1

    This treats total as if each object had its own copy; a static field is shared, so all three increments land on one variable.

  • b
    3 1 Correct

    total is one variable shared by every Counter and is incremented three times; mine belongs to each object and is incremented once per object.

  • c
    3 3

    This treats mine as shared; each new Counter gets its own mine starting at 0, so c.mine is 1.

  • d
    1 3

    This swaps the two kinds of field: the static total is the one that counts every construction.

The concept

A static field has one copy per class; an instance field has one copy per object.

Why that’s the answer

Each new Counter() runs the constructor, which increments the class-wide total and the new object's own mine. After three constructions total is 3. The variable c refers to the third object, whose mine went from 0 to 1. The output is 3 1.

How to reason it out
  1. Identify which field is static (total) and which is per object (mine).
  2. Count constructions: three, so total is incremented three times.
  3. Each object's mine starts at 0 and is incremented once.
  4. Print total, a space, then the third object's mine.

Exam tip: Static fields count across all instances; instance fields start fresh in every object.

Java Classes, Records, Constructors and Initializers (1Z0-831) — the lesson that teaches this.

Question 2Applying Object-Oriented Principles in Java Programs

Given:record Point(int x, int y) {} public class Main { public static void main(String[] args) { Point p = new Point(3, 4); System.out.println(p.x() + p.y()); } }What is the result?

Choose one.

  • a
    7 Correct

    The record supplies accessors x() and y() returning 3 and 4; int + int is numeric addition.

  • b
    34

    Both operands are int, so + adds them; string concatenation needs a String operand on one side.

  • c
    Compilation fails

    A record automatically gets a public accessor method named after each component, so x() and y() exist.

  • d
    0

    The implicit canonical constructor assigns both components, so the accessors return 3 and 4, not default values.

The concept

A record declares its components once; the compiler generates private final fields, a canonical constructor and an accessor named after each component.

Why that’s the answer

record Point(int x, int y) {} produces a canonical constructor Point(int x, int y) that stores both values and accessors x() and y() (no get prefix). p.x() + p.y() adds two ints, 3 + 4, and prints 7. The 34 distractor would need a String operand, and the compile-error distractor assumes accessors must be written by hand.

How to reason it out
  1. Note the record header declares components x and y.
  2. Recall the generated accessors are named x() and y().
  3. The canonical constructor stores 3 and 4.
  4. int + int is arithmetic, so the result is 7.

Exam tip: Record accessors use the component name itself: p.x(), not p.getX().

Java Classes, Records, Constructors and Initializers (1Z0-831) — the lesson that teaches this.

Question 3Applying Object-Oriented Principles in Java Programs

Given:record Item(String name, int qty) {} public class Main { public static void main(String[] args) { System.out.println(new Item("pen", 2)); } }What is the result?

Choose one.

  • a
    Item{name=pen, qty=2}

    Curly braces are a common hand-written or library style; the generated record toString uses square brackets.

  • b
    Item[name=pen, qty=2] Correct

    A record's generated toString prints the record name and each component as name=value inside square brackets.

  • c
    Item(name=pen, qty=2)

    Parentheses mirror the record header, but the generated toString uses square brackets.

  • d
    Item@ followed by a hash code

    That is Object.toString; a record overrides toString to list its components.

The concept

Records generate toString, equals and hashCode from their components.

Why that’s the answer

Item is a record, so the compiler provides a toString that lists each component in declaration order as name=value, separated by commas and wrapped in square brackets after the record's simple name. println calls that toString and prints Item[name=pen, qty=2]. The class-name-and-hash form is what a plain class inherits from Object.

How to reason it out
  1. Recognise Item as a record.
  2. Recall the generated toString format: Name[comp=value, comp=value].
  3. Fill in the components in declaration order.

Exam tip: Record toString looks like Item[name=pen, qty=2] — square brackets, name=value pairs.

Java Classes, Records, Constructors and Initializers (1Z0-831) — the lesson that teaches this.

Question 4Applying Object-Oriented Principles in Java Programs

Given:public class Main { static { System.out.print("S "); } { System.out.print("I "); } Main() { System.out.print("C "); } public static void main(String[] args) { System.out.print("M "); new Main(); new Main(); } }What is the result?

Choose one.

  • a
    M S I C I C

    The static initializer runs as part of initializing Main, which happens before main can be invoked, so S comes first.

  • b
    S M I C I C Correct

    The static block runs once when Main is initialized, before main; each new Main() then runs the instance block and the constructor.

  • c
    S M I C S I C

    A static initializer runs once per class, not once per object; the second new Main() does not repeat it.

  • d
    S M C I C I

    Instance initializer blocks run before the constructor body, not after it.

The concept

Static initializers run once at class initialization; instance initializers run on every construction, before the constructor body.

Why that’s the answer

Launching Main initializes the class, which runs its static block and prints S. main then prints M. Each new Main() runs field initializers and instance initializer blocks (printing I) and then the rest of the constructor body (printing C). Two constructions give I C I C. The full output is S M I C I C.

How to reason it out
  1. Static blocks: once, when the class is initialized (before main runs).
  2. main prints M.
  3. Each new runs instance blocks, then the constructor body.
  4. Repeat the instance part for the second object.

Exam tip: Static: once per class, first. Instance blocks: every new, before the constructor body.

Java Classes, Records, Constructors and Initializers (1Z0-831) — the lesson that teaches this.

Question 5Applying Object-Oriented Principles in Java Programs

Given:class Demo { int a = trace("a"); { trace("block"); } int b = trace("b"); Demo() { trace("ctor"); } static int trace(String s) { System.out.print(s + " "); return 1; } } public class Main { public static void main(String[] args) { new Demo(); } }What is the result?

Choose one.

  • a
    a block b ctor Correct

    Instance field initializers and instance initializer blocks run in the order they appear in the source, then the constructor body.

  • b
    a b block ctor

    This runs all field initializers before blocks; Java runs fields and blocks together in textual order.

  • c
    block a b ctor

    Initializer blocks are not hoisted ahead of field initializers; position in the source decides.

  • d
    ctor a block b

    The constructor body runs last, after every instance initializer has run.

The concept

Instance variable initializers and instance initializer blocks execute in textual order, after the superclass constructor and before the rest of the constructor body.

Why that’s the answer

new Demo() first calls the implicit super() (Object), then runs instance initializers top to bottom: int a = trace("a"), the block calling trace("block"), then int b = trace("b"). Only then does the constructor body run trace("ctor"). Output: a block b ctor.

How to reason it out
  1. The superclass constructor (Object) runs first.
  2. Walk the instance initializers top to bottom, fields and blocks mixed.
  3. Run the constructor body last.

Exam tip: Fields and instance blocks share one queue, in source order.

Java Classes, Records, Constructors and Initializers (1Z0-831) — the lesson that teaches this.

Question 6Applying Object-Oriented Principles in Java Programs

Given:class Pizza { String size; int slices; Pizza() { this("medium"); System.out.print("A "); } Pizza(String size) { this(size, 8); System.out.print("B "); } Pizza(String size, int slices) { this.size = size; this.slices = slices; System.out.print("C "); } } public class Main { public static void main(String[] args) { Pizza p = new Pizza(); System.out.println(p.size + " " + p.slices); } }What is the result?

Choose one.

  • a
    A B C medium 8

    A is printed after this("medium") returns, so it cannot come first; the chain unwinds from the innermost constructor.

  • b
    C B A null 0

    The two-argument constructor assigns both fields before the chain unwinds, so they hold medium and 8.

  • c
    C B A medium 8 Correct

    Each this(...) call runs the target constructor completely before the caller's next statement, so the innermost print comes first.

  • d
    A B C null 0

    Both the order and the values are wrong: the chain prints innermost first and it does set the fields.

The concept

this(...) delegates to another constructor of the same class; the delegated constructor finishes before the delegating one continues.

Why that’s the answer

new Pizza() calls this("medium"), which calls this("medium", 8). That constructor sets size and slices and prints C. Control returns to Pizza(String), which prints B, and then to Pizza(), which prints A. main then prints the fields: medium 8.

How to reason it out
  1. Follow the this(...) calls to the innermost constructor.
  2. Execute it fully: fields assigned, C printed.
  3. Unwind: print B, then A.
  4. Print the fields set by the innermost constructor.

Exam tip: Delegated constructors print inside-out: the last one called finishes first.

Java Classes, Records, Constructors and Initializers (1Z0-831) — the lesson that teaches this.

What 1Z0-831 domain 3 tests, topic by topic

The official exam guide breaks Applying Object-Oriented Principles in Java Programs into 7 topics. The question bank follows the same split, so a weak topic shows up as a cluster of misses you can go back and read.

Published 1Z0-831 practice questions per topic in Applying Object-Oriented Principles in Java Programs
TopicWhat it coversQuestions
Objects, nested classes and the object life cycleOfficial 1Z0-831 objective 3.1: "Declare and instantiate Java objects including nested class objects, and explain the object life-cycle including creation, reassigning references, and garbage collection."25
Classes, records, constructors and initializersOfficial 1Z0-831 objective 3.2: "Create classes and records, and define and use instance and static fields and methods, constructors, including flexible constructor bodies, and instance and static initializers."25
Overloaded and var-arg methodsOfficial 1Z0-831 objective 3.3: "Implement overloaded methods, including var-arg methods."25
Scope, encapsulation, immutability, var and unnamed variablesOfficial 1Z0-831 objective 3.4: "Understand variable scopes, apply encapsulation, and create immutable objects. Use local variable type inference and unnamed variables."25
Inheritance, abstract and sealed types, overriding and polymorphismOfficial 1Z0-831 objective 3.5: "Implement inheritance, including abstract and sealed types as well as record classes. Override methods, including that of the Object class. Implement polymorphism and differentiate between object type and reference type."25
Interfaces, functional interfaces and interface methodsOfficial 1Z0-831 objective 3.6: "Create and use interfaces, identify functional interfaces, and utilize private, static, and default interface methods."25
Enums with fields, methods and constructorsOfficial 1Z0-831 objective 3.7: "Create and use enum types with fields, methods, and constructors."25
Total175

Revise Applying Object-Oriented Principles in Java Programs before you drill it

Other 1Z0-831 domains

Applying Object-Oriented Principles in Java Programs: your questions

Applying Object-Oriented Principles in Java Programs is domain 3 of the 1Z0-831 exam guide and carries 18% of the scored content — the heaviest of the 10 domains. On a 50-question paper that works out to roughly 9 questions, though Oracle does not publish an exact per-domain count and individual exam forms vary.

Source

The domain weight and topic list on this page come from the official 1Z0-831 exam guide.