aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrapper classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Wrapper classes" Watch "Wrapper classes" New topic
Author

Wrapper classes

Neha Sawant
Ranch Hand

Joined: Oct 11, 2001
Posts: 204
1)
public class Test {
public static void main(String[] args)
{
Float f = new Float(32D);
System.out.println(f);
}
}

compiles and prints 32.0.
I thought this should give compiler error because of 32D
whereas
2) public class Test {

public static void main(String[] args){
byte a = 10;
Byte b = new Byte(a);
Byte c = new Byte(11);
System.out.println(b.compareTo(c));
}
}
gives compiler error.
I know this gives compiler error because 11 is int.
3) And why does this give Runtime error.
I thought it should be true
public class Test {

public static void main(String[] args){
Float f = new Float(16/0);
System.out.println(f.isNaN());
}
}


nss
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5288
    
  10

Refer to the JavaDocs: Float has an overloaded constructor that accepts a double. Byte does not have a constructor that takes an int.
16/0 is an integer expression since both operands are integers. Integer division by 0 will generate an ArithmeticException. Make one or both operands a float by using 16.0 or 0.0 or both.
Junilu
------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform


Junilu - [How to Ask Questions] [How to Answer Questions]
Neha Sawant
Ranch Hand

Joined: Oct 11, 2001
Posts: 204
thanx JUNILU
I got it
Regards
Neha
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
hi,
that was cool. i never knew that!!
regards,
maulin.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrapper classes