1Z0-803 · Question #108
Given: package pkg1; class Bb { } public class Ee { private Ee() { } } package pkg2; final class Ww; package pkg3; public abstract class Dd { void m() { } } And, 1. package pkg4; 2. import pkg1.; 3. i
The correct answer is A. class Cc extends Bb { } D. class Cc extends Dd { }. This question tests the understanding of Java class modifiers, constructor visibility, and inheritance rules when classes are defined across packages.
Question
Options
- Aclass Cc extends Bb { }
- Bclass Cc extends Ww { }
- Cclass Cc extends Ee { }
- Dclass Cc extends Dd { }
How the community answered
(32 responses)- A69% (22)
- B22% (7)
- C9% (3)
Why each option
This question tests the understanding of Java class modifiers, constructor visibility, and inheritance rules when classes are defined across packages.
Class `Bb` is a non-final, non-abstract class with a default constructor, making it accessible and extendable by class `Cc` through package import.
Class `Ww` is declared with the 'final' modifier, which explicitly prevents any other class from extending it.
Class `Ee` has a private constructor, preventing any external class, including a subclass, from implicitly or explicitly invoking a superclass constructor during inheritance.
Class `Dd` is an abstract class, explicitly designed for extension, and since it's public and imported, `Cc` can extend it without issue.
Concept tested: Java class inheritance rules and modifiers
Source: https://docs.oracle.com/javase/tutorial/java/IandI/abstract.html
Topics
Community Discussion
No community discussion yet for this question.