Java OCA OCP Practice Question 3271

Question

Given the following code:

public class Main {
  public static void main(String[] args) {
    // (1) INSERT METHOD CALL HERE.
  }
  private static void m(Long lValue){
    System.out.println("Widen and Box");
  }
}

Which method calls, when inserted at (1), will cause the program to print:

Widen and Box

Select the two correct answers.

  • (a) m((byte)10);
  • (b) m(10);
  • (c) m((long)10);
  • (d) m(10L);


(c), (d)

Note

Only primitive types allow automatic widening conversion, wrapper types do not allow automatic widening conversion.

A byte or an int cannot be automatically converted to a Long.

Automatic boxing and unboxing is only allowed between corresponding primitives types and their wrapper classes.




PreviousNext

Related