nerdexam
Oracle

1Z0-803 · Question #119

Given: public class Test { } From which class does the Java compiler implicitly derive Test?

The correct answer is A. Object. All Java classes implicitly extend the java.lang.Object class if they do not explicitly extend another class in their declaration.

Working with Inheritance

Question

Given:

public class Test { } From which class does the Java compiler implicitly derive Test?

Options

  • AObject
  • BClass
  • Can anonymous class
  • DObjects

How the community answered

(36 responses)
  • A
    89% (32)
  • B
    3% (1)
  • C
    6% (2)
  • D
    3% (1)

Why each option

All Java classes implicitly extend the `java.lang.Object` class if they do not explicitly extend another class in their declaration.

AObjectCorrect

In Java, if a class declaration does not explicitly extend another class, the Java compiler automatically makes it a direct subclass of `java.lang.Object`. This ensures that all classes inherit fundamental methods like `equals()`, `hashCode()`, and `toString()`.

BClass

`java.lang.Class` is a class that provides methods for inspecting other classes and objects at runtime, not a default superclass.

Can anonymous class

An anonymous class is a class without a name, typically defined and instantiated in a single expression, and it still implicitly or explicitly extends another class or implements an interface.

DObjects

`java.util.Objects` is a utility class that provides static helper methods for operating on objects, such as null-safe comparisons, not a default superclass.

Concept tested: Java class inheritance hierarchy - java.lang.Object

Source: https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html

Topics

#inheritance#Object class#class hierarchy

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice