aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructor Arguments for Wrapper Class Float Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Constructor Arguments for Wrapper Class Float" Watch "Constructor Arguments for Wrapper Class Float" New topic
Author

Constructor Arguments for Wrapper Class Float

kashish verma
Greenhorn

Joined: Dec 07, 2005
Posts: 13
This question is from danchisholm mock test.

Question 14
class F {
public static void main (String[] args) {
Float f1 = new Float('B' - 'A'); // 1
Float f2 = new Float(010); // 2
Float f3 = new Float(0x10); // 3
Float f4 = new Float(.1e1); // 4
Float f5 = new Float(1.0); // 5
Float f6 = new Float(1.0d); // 6
System.out.print(f1+","+f2+","+f3+","+f4+","+f5+","+f6);
}}

What is the result of attempting to compile and run the program?

a. Compile-time error at 1
b. Compile-time error at 2
c. Compile-time error at 3
d. Compile-time error at 4
e. Compile-time error at 5
f. Compile-time error at 6
g. Run-time error at 1
h. Run-time error at 2
i. Run-time error at 3
j. Run-time error at 4
k. Run-time error at 5
l. Run-time error at 6
m. Prints: 1.0,10.0,10.0,1.0,1.0,1.0
n. Prints: 1.0,8.0,16.0,1.0,1.0,1.0
o. None of the above

Answer is n. -- Reason:The Float constructor is overloaded: one version accepts a primitive of type float; one accepts a primitive of type double; one accepts a String representation of a floating-point literal. All numeric values can be promoted to type double; so all numeric values are accepted by the float constructor.

But in K&B book , P-377, Wrapper Constructors states that :
Float Wrapper Class provides 2 constructor arguments float or String.
B]Then what about double?[/B]
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
just browse the API man.....
u will see that the float contrustor accepts double (surprisingly) and other overloaded constructors

i dont think htat the exam expects you to rember all contructors of all wrapper classes its fine if u learn the table listing all the methods of wrapper classes

niranjan
preaparing for SCJP1.4


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228

dont think htat the exam expects you to rember all contructors of all wrapper classes its fine if u learn the table listing all the methods of wrapper classes


It does. As far as i know, you need to know the constructors of wrapper classes. You can see many good question's from Dan's mock which really focuses on this part.
[ December 07, 2005: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
kashish verma
Greenhorn

Joined: Dec 07, 2005
Posts: 13
that is fine, but then why it is not in K & B book.
Or did i miss it?
Coz table 6-2 on page no. 377 ,specifies float or String for Float class.
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
why it is not in K & B book.

I'm not sure about it. But it's always advisable to browse java docs along with what ever books yo have.
kashish verma
Greenhorn

Joined: Dec 07, 2005
Posts: 13
thanks Srini.
 
jQuery in Action, 2nd edition
 
subject: Constructor Arguments for Wrapper Class Float