• 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

About switch...

 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at following code...

at line marked as 1 , compiler complains as
variable k might not have been initialised
I don't understand why?? if k is not visible to case 3 block , it should have given the error...
variable k undefined.
And if it is visible (in scope on case 3 block) then k is initialised , then why the the copiler complains...
thanx in advance.
Rashmi
 
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
k would be initialized only the switch statement hits the case2 and k is a local variable so it does not get initialized auto.
------------------
Have a nice day, Unless you've made other plans.
 
reply
    Bookmark Topic Watch Topic
  • New Topic