Java OCA OCP Practice Question 2115

Question

Choose the correct option based on this program:.

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
         String[] brics = {"Brazil", "Russia", "India", "China"};
         Arrays.sort(brics, null);    // LINE A
         for(String country : brics) {
             System.out.print(country + " ");
         }//from   w  ww. j  a  va2 s. com
    }
}
  • a . this program will result in a compiler error in line marked with comment line a
  • B. When executed, the program prints the following: Brazil russia india China
  • C. When executed, the program prints the following: Brazil China india russia
  • d. When executed, the program prints the following: russia india China Brazil
  • e. When executed, the program throws a runtime exception of NullPointerException when executing the line marked with comment line a
  • F. When executed, the program throws a runtime exception of InvalidComparatorException when executing the line marked with comment line a


C.

Note

When null is passed as a second argument to the Arrays.sort() method, it means that the default Comparable (i.e., natural ordering for the elements) should be used.

the default Comparator results in sorting the elements in ascending order.

the program does not result in a NullPointerException or any other exceptions or a compiler error.




PreviousNext

Related