This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner class code example

 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I tried out the following code :



The result is 21. My question is how can class Gazer access a static variable? I mean we are trying to access a static member of the outer class from a non static context. So it should throw an exception right?
 
Paul Clapham
Sheriff
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's never anything wrong with accessing a static member from a non-static context.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:There's never anything wrong with accessing a static member from a non-static context.


Ohhh.. Ok.. So the problem is when we try to access a non static member from a static context. Correct Paul? That will upset the compiler right?
 
Paul Clapham
Sheriff
Pie
Posts: 20177
25
MySQL Database
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:So the problem is when we try to access a non static member from a static context. Correct Paul? That will upset the compiler right?


Yes, I'm sure you must have seen that message already, haven't you?
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Mansukhdeep Thind wrote:So the problem is when we try to access a non static member from a static context. Correct Paul? That will upset the compiler right?


Yes, I'm sure you must have seen that message already, haven't you?


Thank you Paul.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic