Java OCA OCP Practice Question 3223

Question

Which statements are true about the following code?

class A {/*from  w w  w  .  j  av a 2 s . com*/
  public A() {}

  public A(int i) { this(); }
}

class B extends A {
  public boolean B(String msg) { return false; }
}

class C extends B {
  private C() { super(); }

  public C(String msg) { this(); }

  public C(int i) {}
}

Select the two correct answers.

  • (a) The code will fail to compile.
  • (b) The constructor in A that takes an int as an argument will never be called as a result of constructing an object of class B or C.
  • (c) Class C defines three constructors.
  • (d) Objects of class B cannot be constructed.
  • (e) At most one of the constructors of each class is called as a result of constructing an object of class C.


(b) and (c)

Note

Statement (d) is false, since an object of B can be created using the implicit default constructor of the class.

B has an implicit default constructor since no constructor has explicitly been defined.

Statement (e) is false, since the second constructor of C will call the first constructor of C.




PreviousNext

Related