• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

local inner classes

 
Akhil Gupta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please can somebody tell me if we can declare inner classes with in a method to be static or private. If i compile it, it gives me a error, although error it shows is different, but is due to that only, whereas as Khalid-Mughal and marcus green exam 1 question no. 30 says so. Please help me about it
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Akhil,
You must have missed it in KM book (page 238)
Local classes can NOT have any accessibility specified.
The class is defined as static or not depending on whether the method is static or not. For example, a local class defined in a static method will be considered static, while a local class defined in a non-static method will be considered non-static.
Regards,
Manfred.
 
Jyotsna Umesh
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Manfred,
Please explain that if local class in a staic method is defined as static though it is implicitly static becoz of the method being static), will it be wrong?
Regards
Jyotsna Umesh
 
Prakshi Chopra
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Akhil
if you declare inner class inside a static method using static modifier compiler will give error.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic