Wednesday, January 30, 2013

Lesson 21 Excercise


Lesson 21 Exercise
Matthew Walker
Balcar 3A 1/30/13
  1. The classes that convert primitives to objects are called Wrapper classes.

  1. Name the four primitive data types with which wrapper classes primarily deal.
Integer, Double, Boolean,Character

3. Write code that will convert double dx into a wrapper class object. Call the object dd.
   

4. Write code that will produce a Boolean type wrapper object called bj (“wrap” a true
inside it).
    boolean bj = bObj.booleanValue( 5<7);

5. Write code that will convert the integer ip into an Integer wrapper class object. Call the
object ozzie.

6. Assume you have the object Character cw. Write code to convert this to a primitive
character.

7. Assume you have Double objects d1 and d2. Show how you would multiply the values
stored in these objects and then store the answer in primitive double dd.

8. Assume you have Integer objects i1 and i2. Show how you would add the values stored
in these objects and then store the answer in a third Integer object called i3.

9. Write code that will extract the boolean wrapped in the Boolean wnOh and test it with an
if statement.
if ( )

10. Convert the object jj (of type Double) into a primitive float called ff.

11. Convert the object pk (of type Double) into a primitive int called gurg. What is the
danger of doing this?

12. What is the primary purpose of wrapper classes?

No comments:

Post a Comment