Win a copy of Microservices in Action this week in the Web Services forum!
  • 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

static inner class.  RSS feed

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
one query---Is it illegal to associate a static class reference with a reference of its enclosing class?( e.g. in the following code)
code:
_____________
public class top {
static class inner {
void show() {
System.out.println("show() in inner");
}
}
public static void main(String []args) {
inner i = new top().new inner();
i.show();
}
}
_____________
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you donot need to instantiate the outer class.
The static class can be invoked directly. For eg, if
Inner class is an static (top-level nested class ) and Outer
is a outer class then we just need to do the following :

Outer.Inner inner = new Outer.Inner();
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it is just like reffering to any static member of a class, for example in
class Temp
{
static i;
}
Here i can be reffered as Temp.i or temp.i where Temp temp = new Temp.

Originally posted by ashok khetan:
hi,
one query---Is it illegal to associate a static class reference with a reference of its enclosing class?( e.g. in the following code)
code:
_____________
public class top {
static class inner {
void show() {
System.out.println("show() in inner");
}
}
public static void main(String []args) {
inner i = new top().new inner();
i.show();
}
}
_____________


 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashok,
It is not illegal, though not required to instantiate an outer class to access a static inner class.
I guess im not wrong.
Anurag
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anurag is right...



Shyam
[This message has been edited by Shyamsundar Gururaj (edited September 12, 2001).]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!