This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception" Watch "Exception" New topic
Author

Exception

Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485


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...
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
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

Joined: Mar 02, 2005
Posts: 580
(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
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Mar 02, 2005
Posts: 580

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
 
GeeCON Prague 2014
 
subject: Exception