Java OCA OCP Practice Question 1825

Question

This question may be considered too advanced for this exam.

Given:

String mStr = "123";
long m = // 1

Which of the following options when put at // 1 will assign 123 to m?

Select 3 options

A. new Long (mStr);
B. Long.parseLong (mStr);
C. Long.longValue (mStr);
D.  (new Long ()).parseLong (mStr);
E. Long.valueOf (mStr).longValue ();


Correct Options are  : A B E

Note

For A.

Auto unboxing will occur.

For C.

longValue is a non-static method in Long class.

For D.

Long (or any wrapper class) does not have a no-args constructor, so new Long() is invalid.

For E.

Long.valueOf(mStr) returns a Long object containing 123.longValue() on the Long object returns 123.




PreviousNext

Related