Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method local inner class question from marcus green mock exam 1

 
Veena Pointi
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The ans given is 1,2,3
But none of the answers are correct right?Coz method local inner class can't be declared as public,private,protected,static,as class is defined locally inside a method.Please correct me if I am wrong.
Thanks
Veena
 
Vivek Nidhi
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you got some confusion with ordinary classes and inner classes.The ordinary class you can have no modifies other than public.In case of Inner classes u can have private, protected, public, default and static. U can refer with JLS for confirmation and plz read K&B, you will get every thing clear on this
Vivek Nidhi
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Veena --
You're right, method-local inner classes can't be public, protected, private or static. But looking at the code you've shown here, the inner class is outside of main(), at class scope; it's not a method-local class at all. Such a class can indeed have all these modifiers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic