• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Doubt in Mock test

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public static void main(String[] args) {
boolean b2= Boolean.parseBoolean("true");
Boolean b3= Boolean.valueOf("true");
if(b2){
System.out.println("boolean value");
}
if (b3)
{
System.out.println("boolean object");

}
}
Here the second if statement should give the compilation error because b3 is not primitive boolean type.But while compilation of this prog there is no error.Please explain how it works?
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sukhavasi,

Which compiler are you using for this java code?

In the JDK 1.5, they have introduce the new feature called AutoBoxing and UnBoxing.
According to this feature, whenever require any primitive will be converted to Wrapper object or vice versa.

So, in your case also b3 will be converted to primitive value.

If you are preparing for SCJP 1.4 then, you don't require to know about this feature, otherwise you must know.
 
I was born with webbed fish toes. This tiny ad is my only friend:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic