Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inner classes?  RSS feed

 
Ranch Hand
Posts: 534
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
 
Rancher
Posts: 2862
32
  • 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.
 
author
Marshal
Posts: 23438
138
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: 534
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: 534
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?
 
Bartender
Posts: 1775
45
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: 534
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!