aspose file tools*
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Nested classes" Watch "Nested classes" New topic
Author

Nested classes

vi ch
Greenhorn

Joined: Jan 09, 2002
Posts: 3
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
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.
-Thanks
BTW Your name doesn't follow the standards
somebody is gonna tell u
[ January 17, 2002: Message edited by: Arsho, Ayan ]
 
 
subject: Nested classes