‹ Back to the paper
Question 2(a)
2 marks
Computer ScienceISC 2018 Computer Science Paper 1Short answerPrimitive values, Wrapper classes, Types and casting
Answer the following.
What are Wrapper classes? Give any two examples.
Answer
Answer
Wrapper classes are classes provided by Java that 'wrap' (encapsulate) a primitive data type inside an object, so that a primitive value can be treated as an object (e.g. for use in collections, or to access utility methods such as converting/parsing strings to numbers). Every primitive type has a corresponding wrapper class.
Examples: Integer (wraps int), Character (wraps char) - (any two, e.g. Double for double, Boolean for boolean, are equally acceptable).