GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes a ques from j@whiz 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 "a ques from j@whiz" Watch "a ques from j@whiz" New topic
Author

a ques from j@whiz

sameebh
Greenhorn

Joined: Nov 08, 2001
Posts: 1
I have a doubt in the given code.Can a method have
another method inside it ?. i am confused about this concept. kindly help.
according to me,this prg should not work.
CODE:
what variable may be refered correctly at HERE.
THE CODE IS TAKEN FROM J@WHIZ SIMULATOR
public class Outer{
public int a=1;
prvate int b=2;
public void method(final int c)
{
int d=3;
class inner
{
private void imethod(int e)
{
HERE
}
}
}
}

choose the all the right options :
1) a
2) b
3) c
4) d
5) e
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
sameebh,
the given code is correct. What we have here is a class local to the method method(). And this is perfectly legal. The only requirement for such classes is that they may only access final local variables and any variable of the enclosing class.
In this case the correct answers are a,b because they are freely referencable from the local inner class, c because it is a final (read constant) variable in the method context and e because it is a parameter to the method imethod().
Also, I'd like you to read the Javaranch Naming Policy and register again.
Thank you for your cooperation
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
GeeCON Prague 2014
 
subject: a ques from j@whiz