• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

ExamLab Question.

 
Greenhorn
Posts: 20
Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given the following code fragment:


For any non null argument, %b returns true. So in line 6 we get true. However in line 7 'format("%b",new Boolean(b)).toString();' returns false. Please explain.
 
Bartender
Posts: 5631
214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pritha Banerjee wrote:
For any non null argument, %b returns true.


No. Have a look at the API of the class Formatter, especially what it says about the %b conversion.
When the argument is not null, then it makes a discrimination between a boolean argument and a non-boolean.

Nasty trick-questions...
 
Pritha Banerjee
Greenhorn
Posts: 20
Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'For "%b" : If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(). Otherwise, the result is "true".' I got it, thanks Piet
 
reply
    Bookmark Topic Watch Topic
  • New Topic