File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Nested classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Nested classes" Watch "Nested classes" New topic

Nested classes

vi ch

Joined: Jan 09, 2002
Posts: 3
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.
Arsho, Ayan
Ranch Hand

Joined: Nov 14, 2001
Posts: 60
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.
BTW Your name doesn't follow the standards
somebody is gonna tell u
[ January 17, 2002: Message edited by: Arsho, Ayan ]
I agree. Here's the link:
subject: Nested classes
It's not a secret anymore!