Email address:
Password:
SCJP/OCPJP 1.6 certification
Practice Exams and Training

16. int i=(byte)4;

17. byte b=(byte)i;

18. short s=b;

19. char c=(char)s;

20. java.lang.Character c2=(Byte)(new java.lang.Byte("4"));

21. char c3=new Character('A').charValue();

22. byte b2=new java.lang.Byte(4);

23. java.lang.Float ft=Float.valueOf("45T").floatValue();

24. java.lang.Float ft2=Float.parseFloat("45T").floatValue("32F");


Why Line 24 shows compile error

From the explanation:


"Line-24 gives a compile time error, because the method Float.parseFloat(String) returns a float primitive value - not a Float wrapper object. You cannot call a method 'of' a primitive value. The compiler fails to compile saying "float cannot be dereferenced"."


So, basically, the expression Float.parseFloat("45T") is supposed to return a primitive float value (not the wrapper Float with uppercae-F). Then you are trying to call another method (floatValue("32F")) on that float value, which causes the compile error.


To make it even simpler, you are kind of trying to do this:


float f = 23467;
f.floatValue("32F");


The above code doesn't work because f is a primitive float value, and therefore you can't call any methods on it.

ExamLab © 2008 - 2024