Multiple choice technology programming languages

package constructors; class R { R() { } } class S extends R { int p ; S() { this(10); super(); System.out.println("I am in Q"); } S(int p) { this.p = p; System.out.println("I am in Q with Argument"); } } public class TestConstructor4 { Q q = new Q(); }

  1. Exception

  2. I am in Q I am in Q with Argument

  3. I am in Q

  4. Compiler Error

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Java constructors must call either this() or super() as the first statement, but not both. The code S() { this(10); super(); } attempts to call both this(10) and super() in the same constructor, which is illegal. The compiler rejects this because super() is automatically inserted by the compiler if no this() or super() call exists, but if this() is present, the compiler won't insert super(). Additionally, the code references classes R and S but TestConstructor4 creates Q, and uses class Q without declaring it - multiple compilation errors exist.