• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Nested classes

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
1. Can anyone tell me if you can have nested classes without the keyword static?
In the book , " Just Java", Fourth Edition, Sun Microsystems, Peter van der Linden gives the following example.

class Hastable{
private Entry []myTable;
//other class variables
static class Entry{
int hash;
\\other variables
}

}
In another class
Hastable.entry he=new hashtable.Entry();
int i=he.hash;
2. My question is the class Hashtable is not a static class. How can it be refenced as a class name, without declaring an object.
Thanks a bunch.
Vidyu
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer to Question 1 :
Yes you can have nested classes without static keyword.
Answer to Question 2 :
Hastable is a Top level class meaning it cannot be declared static.Static classes are referred in the following way
Hastable.entry he=new hashtable.Entry();
similar to a package naming structure.
-Thanks
BTW Your name doesn't follow the standards
somebody is gonna tell u
[ January 17, 2002: Message edited by: Arsho, Ayan ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic