Monday's Programming Question
This week it's the turn of wrapper classes to take the spotlight. Every primitive data type has a corresponding class. These classes are handy if you want to make the primitive data type into an object. For example, the data type int has a corresponding wrapper class called Integer.
It's important to remember that the wrapper classes are not the same as primitive data types and will act differently in certain circumstances. In the following lines of code I've been playing with wrapper classes. The question is can you figure out what the values of the wrapper objects will be?
Boolean eminem = new Boolean("yes");
Boolean lLCoolJ = new Boolean("true");
Integer mosDef = new Integer(Integer.MAX_VALUE+1);
Long queenLatifah = new Long(Integer.MAX_VALUE+1);
Long iceCube = new Long((long)Integer.MAX_VALUE + 1);
Long jayZ = new Long(iceCube++);
Long kanyeWest = new Long(++iceCube);
Character snoopDogg = new Character("c".replace("c", "d").toCharArray()[0]);
Double theGame = new Double(Double.POSITIVE_INFINITY);
Double common = new Double (Math.round(Double.POSITIVE_INFINITY));
Integer nas = 10444;
Integer trickTrick = 10444;
Boolean lilWayne = (nas == trickTrick);
Boolean bowWow = (nas.equals(trickTrick));


No comments yet. Leave a Comment