• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Constructor Arguments for Wrapper Class Float

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 ]
 
kashish verma
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Srini.
 
reply
    Bookmark Topic Watch Topic
  • New Topic