• Post Reply Bookmark Topic Watch Topic
  • New Topic

Default initialization  RSS feed

 
N Sam
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remember reading Instance variables & local variables (in methods) are initialized to appropriate value by the compiler. (Please supply appropriate definition, if i am wrong).
Is this true for static class variables and variables in nested classes ?
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Compiler only put default value for the instance variables and static variables. We need to initialize value for local variables otherwise compiler error comes. For the nested class variables are also initialized by compiler to default but any variable defined inside method of nested class also treated as local and need to initialize.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!