• 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

Exception

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


compiler error at line 1

please explain me


P.S:i donno why peoples are not replying to my post please do reply.... though it is having silly questions...
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi paramesh

I think scope of object p in the try block is over when block ends
if u move the println statement next to object creation statement it works
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(sorry friends i click the enter button mistakenly
Hi paramesh

I think scope of object p in the try block is over when block ends
if u move the println statement next to object creation statement it works
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

The compilation error is caused by a problem in the variable scope "p".

p is defined inside the try{} and is not accesible after the "catch".

If you want to use this variable outside the catch you must declare it outside the try:


Param p = null;
try{
p = new Param();
} catch {

}

System.out.println(p.a);
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


P.S:i donno why peoples are not replying to my post please do reply.... though it is having silly questions...



Take it in a correct sense

your are asking basic doubt......i hope UR not understood basic concepts correctly otherwise UR not thinking for sometime before asking
 
Danger, 10,000 volts, very electic .... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic