Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a ques from j@whiz

 
sameebh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic