• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inner classes?  RSS feed

 
Adam Chalkley
Ranch Hand
Posts: 518
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just wondering why a few things are legal and not  number one how come it is possible to call out class variables from the inner class even ones that are private? but it's not possible to call methods of the outerclass from the inner class?



two,even when I create an instance of the outer class in the inner class I still get an error





thanks
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still get an error 

It would help if you copied the full text of the compiler's error message and pasted it with your post.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Chalkley wrote:but it's not possible to call methods of the outerclass from the inner class?


Adam Chalkley wrote:two,even when I create an instance of the outer class in the inner class I still get an error


Java statements, that are not declarations, must be defined in a method, constructor, or initializer. It can't just be placed anywhere.

Also, this is true for any class definition, so, these errors are not just related to inner classes.

Henry
 
Adam Chalkley
Ranch Hand
Posts: 518
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply guys

Henry I'm not too sure what you mean could you elaborate please

thanks
 
Adam Chalkley
Ranch Hand
Posts: 518
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I understand so method can only be called inside or methods or constructors pretty much?
 
salvin francis
Bartender
Posts: 1649
37
Eclipse IDE Google Web Toolkit Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Chalkley wrote:I think I understand so method can only be called inside or methods or constructors pretty much?

Pretty much right,
Here is a sample code where you can call methods:

 
Adam Chalkley
Ranch Hand
Posts: 518
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Salvin
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!