OCA Java SE 8 Method - OCA Mock Question Method 13


Which of the following can replace line 2 to make this code compile?

     1: import java.util.*; 
     2: // INSERT CODE HERE 
     3: public class Main { 
     4:    public void method(List<String> list) { 
     5:       sort(list); 
     6:    } 
     7: } 
  1. import static java.util.Collections;
  2. import static java.util.Collections.*;
  3. import static java.util.Collections.sort(List<String>);
  4. static import java.util.Collections;
  5. static import java.util.Collections.*;
  6. static import java.util.Collections.sort(List<String>);




To import static methods from we can do

import static java.util.Collections.*; 
import static java.util.Collections.sort;

A is incorrect since you cannot do a static import on non-static members.

C is wrong since method parameters are not needed.

D, E, and F reverses the syntax of import static.