Bird
0
0

Which statement about wrapper class methods is TRUE?

hard📝 Conceptual Q10 of 15
Java - Wrapper Classes
Which statement about wrapper class methods is TRUE?
AvalueOf methods always return primitive types
BparseXxx methods return wrapper objects
CvalueOf methods can return cached objects for some values
DparseXxx methods throw NullPointerException on null input
Step-by-Step Solution
Solution:
  1. Step 1: Understand valueOf method behavior

    valueOf methods return wrapper objects, sometimes cached for efficiency (e.g., Integer between -128 and 127).
  2. Step 2: Check parseXxx and exception behavior

    parseXxx methods return primitives, not objects. They throw NumberFormatException on null, not NullPointerException.
  3. Final Answer:

    valueOf methods can return cached objects for some values -> Option C
  4. Quick Check:

    valueOf caches some wrapper objects [OK]
Quick Trick: valueOf caches small values, parseXxx returns primitives [OK]
Common Mistakes:
  • Thinking valueOf returns primitives
  • Assuming parseXxx returns objects
  • Confusing exception types on null input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes