Multiple choice technology programming languages

package constructors; class U { U() { System.out.println("I am in U"); } } class V extends U { void V() { System.out.println("I am in V"); } } public class TestConstructor5 { public static void main(String[] args) { V v = new V(); } }

  1. I am in U

  2. Compiler Error

  3. I am in V

  4. I am in U I am in V

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

When V() is instantiated, the default constructor of V calls super() implicitly, which invokes U's constructor. U's constructor prints "I am in U". The method void V() in class V is NOT a constructor - it has a return type (void), so it's just a regular method that never gets called during object creation. Only U's constructor executes. This is a common trick question testing whether you recognize that constructors cannot have return types.