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

Anonymous class

 
Milan Sutaria
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Inside main method an anonymous class is created which is a sublclass of Thread class. How can it access the go method without the class name ( B.go() )?
 
Bob Ruth
Ranch Hand
Posts: 320
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inner classes have access to all members of the enclosing outer class.
 
Milan Sutaria
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was thinking something else .... thanks for helping out.
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although you have got your answer but still I would like to explain it here
As you might know All Inner classes are compiled into top level classes.
When an anonymous class accesses the members of its enclosing class at compile time the compiler will add the name of the enclosing class at the statement where you are accessing the enclosing class member(static).
So your code after compilation will become-

[ August 05, 2008: Message edited by: AnkitJi Garg ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic