Which of the following are true about the following code?
Choose all that apply
public class Main { Main() { /*from w w w. j a v a2 s . co m*/ System.out.print("1 "); } Main(int num) { System.out.print("2 "); } Main(Integer num) { System.out.print("3 "); } Main(Object num) { System.out.print("4 "); } Main(int... nums) { System.out.print("5 "); } public static void main(String[] args) { new Main(100); new Main(1000L); } }
A, E.
The 100 parameter is an int and so calls the matching int constructor.
When this constructor is removed, Java looks for the next most specific constructor.
Java prefers autoboxing to varargs, and so chooses the Integer constructor.
The 100L parameter is a long.
Since it can't be converted into a smaller type, it is autoboxed into a Long and then the constructor for Object is called.