Bird
0
0

Which constructor declaration correctly overloads the following constructor?

easy📝 Conceptual Q2 of 15
Java - Constructors

Which constructor declaration correctly overloads the following constructor?

public class Book {
public Book(String title) { }

Choose the correct overloaded constructor:

Apublic Book(String title) { }
Bpublic Book(String title, int pages) { }
Cpublic void Book(int pages) { }
Dpublic Book() String { }
Step-by-Step Solution
Solution:
  1. Step 1: Identify the original constructor

    The original constructor takes a single String parameter.
  2. Step 2: Check each option

    public Book(String title, int pages) { } has a different parameter list (String, int), so it overloads correctly.
    public Book(String title) { } has the same parameter list, so it is not overloading but duplicate.
    public void Book(int pages) { } is not a constructor because it has a return type void.
    public Book() String { } has invalid syntax.
  3. Final Answer:

    public Book(String title, int pages) { } -> Option B
  4. Quick Check:

    Overloaded constructors must differ in parameter list. [OK]
Quick Trick: Overloaded constructors differ by parameter types/count. [OK]
Common Mistakes:
  • Adding return type to constructor making it a method.
  • Using same parameter list as original constructor.
  • Incorrect syntax in constructor declaration.

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes