nerdexam
Oracle

1Z0-803 · Question #193

Given the code fragments: What is the result?

The correct answer is A. Super. This question tests understanding of method invocation in Java inheritance, specifically when a superclass's method implementation is executed.

Working with Inheritance

Question

Given the code fragments:

What is the result?

Exhibit

1Z0-803 question #193 exhibit

Options

  • ASuper
  • BContract
  • CCompilation fails at line n1
  • DCompilation fails at line n2

How the community answered

(29 responses)
  • A
    55% (16)
  • B
    7% (2)
  • C
    14% (4)
  • D
    24% (7)

Why each option

This question tests understanding of method invocation in Java inheritance, specifically when a superclass's method implementation is executed.

ASuperCorrect

The code fragment likely involves an instance where either a superclass method is called directly, or a subclass's overridden method explicitly invokes `super.methodName()` to execute the parent class's implementation, resulting in 'Super' being printed.

BContract

This output would only occur if a subclass's overridden method that prints 'Contract' was invoked and did not then call its superclass's method, or if there was a separate method printing 'Contract' that was executed.

CCompilation fails at line n1

There is no inherent syntax error or logical flaw suggested by the output 'Super' that would cause a compilation failure at a specific line 'n1'.

DCompilation fails at line n2

There is no inherent syntax error or logical flaw suggested by the output 'Super' that would cause a compilation failure at a specific line 'n2'.

Concept tested: Java inheritance method invocation and `super`

Source: https://docs.oracle.com/javase/tutorial/java/IandI/super.html

Topics

#inheritance#method overriding#polymorphism#compilation errors

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice