Multiple choice technology programming languages

  1. package test1; 2. public class Test1 { 3. static int x = 42; 4. } 1. package test2; 2. public class Test2 extends test1.Test1 { 3. public static void main(String[] args) { 4. System.out.println(“x = “ + x); 5. } 6. } What is the result?

  1. Compilation fails because of an error in line 2 of class Test2.

  2. x = 42

  3. Compilation fails because of an error in line 3 of class Test1.

  4. Compilation fails because of an error in line 4 of class Test2.

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

The compilation fails in Test2 (line 2) because the class extends 'test1.Test1' but this package reference is not imported. To use a class from another package, you need to import it first: 'import test1.Test1;'. Line 2 of Test2 is where Test1 is referenced without an import statement.