• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

inner classes example  RSS feed

 
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>>>But what happens if there is no existence of this for the class Outer. To make sense of the rather odd syntax provided for this try to think of the keyword new as used in the above example as belonging to the current insistence of this.

Thus you could change the line that creates the instance of this to read

Inner i = this.new Inner();
Thus if you need to create an instance of Inner from a static method or somewhere else where there is no this object you can use new as a method belonging to the outer class

class Outer{
public class Inner{}
}

class another{
public void amethod(){
Outer.Inner i = new Outer().new Inner();
}
}

I was reading above lines from link
http://www.jchq.net/certkey/0401certkey.htm

did not understand it clearly.


Any ideas, resources,sample code,links, highly appreciated. thanks in advance.
 
Marshal
Posts: 64493
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thinking in Java by Bruce Eckel.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!