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()); } }
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