• 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

Default values for static Wrapper...

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

What is the default value assigned to the static values of Wrapper class of all types.

To much of my surprise i found static Integer x; as a instance varibale takes a default value of NULL!

Please explane me why?
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From my knowledge, any instance variables which are object references (and so, references to wrapper classes), be it static or non-static, will get the default variable "null". And if the instance variables are primitive, then they get 0 (for byte/short/int/long), 0.0 (for float/double) and '\u0000' for char, and false for boolean. The exception here is a final variable, which has to be given a value (either in the class's instance variable declarations, or within the constructor).

This is not the case with local (or automatic) variables. You will get a compiler error if you use these variables without assigning any values.

Thanks,
-Vijay
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As long as you don't declare a new instance,
I don't see where the surprise is in the variable being null.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic