Which of the following are true about the following code? (Choose all that apply)
public class Main { Main() { 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(1); new Main(1L); } }
A, E.
1 is an int and so calls the matching int constructor.
When this constructor is removed, Java chooses the Integer constructor.
1L is a long and can't be converted into a smaller type, it is autoboxed into a Long and then the constructor for Object is called.