Java OCA OCP Practice Question 1684

Question

Given the following code:.

// (1) INSERT ONE IMPORT STATEMENT HERE
public class Main {
  public static void main(String[] args) {
    System.out.println(sqrt(49));
  }
}

Which statements, when inserted at (1), will result in a program that prints 7, when compiled and run?.

Select the two correct answers.

  • (a) import static Math.*;
  • (b) import static Math.sqrt;
  • (c) import static java.lang.Math.sqrt;
  • (d) import static java.lang.Math.sqrt();
  • (e) import static java.lang.Math.*;


(c) and (e)

Note

The name of the class must be fully qualified.

A parameter list after the method name is not permitted.

(c) illustrates single static import and (e) illustrates static import on demand.




PreviousNext

Related