• Post Reply Bookmark Topic Watch Topic
  • New Topic

initialization  RSS feed

 
saravanan ragunathan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

this pgm generates copilation error that con,rsand st variables may not be initialized
eventhough i initializes the refrences for those variables in try block.why....


 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Initialize them to null:
 
saravanan ragunathan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why i have to intialize them to null eventhough i have
intialized them by returning the referneces through the
methods ...
 
Bharath Raja
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saravanan ragunathan wrote:why i have to intialize them to null eventhough i have
intialized them by returning the referneces through the
methods ...


please remember the rule for local members... since you have declared your references within main(), that is also a method, right,.. then we need to expilicitly intialize with some value...
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saravanan ragunathan wrote:why i have to intialize them to null eventhough i have
intialized them by returning the referneces through the
methods ...


If class.forName(driver); throws an exception then they won't have been initialised when they are referenced in the finally block.
If you do initialise them to null, then you will need to check that they are not null in the finally block
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Careful about spellings, please; your first post is very hard to read.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!