• 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
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

static inner class.

 
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).]
 
Your mother was a hamster and your father was a tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic