Question:

which of the following will happen?

import java.util.Arrays;
import java.util.Comparator;

public class X {

  private int x;

  public X(int x) {
    this.x = x;
  }

  public String toString() {
    return Integer.toString(x);
  }

  public static void main(String[] args) {
    X[] array = new X[3];
    array[0] = new X(3);
    array[1] = new X(1);
    array[2] = new X(2);

    Arrays.sort(array, new Comparator() {
      public int compare(X x1, X x2) {
        return x2.x - x1.x;
      }
    });

    System.out.println(Arrays.toString(array));
  }
}

Answers:


Keywords:

© 2017 QuizBucket.org