Difficulty: Easy
Correct Answer: public Test()
Explanation:
Introduction / Context:
When you do not declare any constructor, the Java compiler provides a no-argument default constructor. Understanding its signature and access level is important for instantiation and subclassing.
Given Data / Assumptions:
Test
.
Concept / Approach:
The compiler synthesizes a no-arg constructor with the same access level as the class. In this case the class is public, so the generated constructor is public Test()
. Java does not use void
in constructor parameter lists, so signatures like Test(void)
are invalid.
Step-by-Step Solution:
public Test()
.
Verification / Alternative check:
Decompile the compiled class or use javap -p Test
to confirm the generated constructor signature.
Why Other Options Are Wrong:Test()
misses the required public modifier; Test(void)
and public Test(void)
are illegal; protected Test()
has the wrong access.
Common Pitfalls:
Thinking constructors can declare a return type or void
; forgetting that visibility matches the class when synthesized.
Final Answer:
public Test()
Discussion & Comments