Constructors

AP Computer Science A· difficulty 3/5

public class Bug {
    private int n;
    public Bug(int n) { this.n = n; }
}
// ...
Bug b = new Bug();

What is the result?

  • A

    Compile-time error: no matching constructor

    check_circle
  • B

    0

  • C

    Run-time error

  • D

    null

Explanation

Once an explicit constructor is declared, the no-argument default constructor is not generated.

Want 10 more like this — adaptive to your weak spots?

Related questions

AP Computer Science A · Constructors Practice Question | Acemy