Multiple choice technology programming languages

Analyze the following code. public class Test { int x; public Test(String t) { System.out.println("Test"); } public static void main(String[] args) { Test test = new Test(); System.out.println(test.x); } }

  1. The program has a syntax error because System.out.println method cannot be invoked from the constructor.

  2. The program has a syntax error because x has not been initialized.

  3. The program has a syntax error because you cannot create an object from the class that defines the object.

  4. The program has a syntax error because Test does not have a default constructor.

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

The Test class defines a constructor with a String parameter (Test(String t)), so Java does NOT auto-generate a no-argument constructor. The main method tries to call 'new Test()' which requires a no-argument constructor that doesn't exist. This is a compilation error, not a runtime error or issues with printing.