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.
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)- A89% (32)
- B3% (1)
- C6% (2)
- D3% (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.
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()`.
`java.lang.Class` is a class that provides methods for inspecting other classes and objects at runtime, not a default superclass.
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.
`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
Community Discussion
No community discussion yet for this question.