aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Using static class 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 "Using static class" Watch "Using static class" New topic
Author

Using static class

ricky gonzalez
Ranch Hand

Joined: Jun 30, 2000
Posts: 167
Hi, I wonder how we use static classes. Do we instantiate them? What exactly are they differing from regular classes?
Thanks!
zulfiqar raza
Ranch Hand

Joined: Oct 18, 2000
Posts: 81
Do you mean Static Member classes? also known as Top-Level Nested Classes.
These classes can be used as any regular Top level classes. They can be instantiated without an outer instance associated with them and can also define both static and non-static members, like any top level package member. However they can also access Static members from the enclosing class.
Zulfiqar Raza
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
A free-standing top level class cannot be static. A static class can exist only within the context of another class. Static InnerClasses are not associated with an instance of outer ( enclosing ) class.

Usually static member classes( aka nested class ) are used as helper classes for the enclosing class.
Hope that helps!
Ajith

[This message has been edited by Ajith Kallambella (edited November 08, 2000).]


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Subha Guhan
Greenhorn

Joined: Nov 06, 2000
Posts: 23
Ajith
I have some doubts if the methods are IMPLICITLY STATIC.
I read in Khalid Nested Top level classes can have both static
and non static methods.
I tried it out

Correct me if I am wrong.
Subha
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Yes, you are right and my wordings were confusing
I have edited my post to make it clearer
Thanks!
Ajith
SHALINI PATEL
Ranch Hand

Joined: Oct 31, 2000
Posts: 41
Subha,
I have a doubt regarding your example,
Here yu r calling a non static method in the main which is static, Is this valid? I mean by calling it even through object reference i.e o1.nonstaticmethod().......... I cant understand this, can yu explain it more clearly... Hope I dont sound so silly.

SHALINI
Sasikanth Malladi
Ranch Hand

Joined: Nov 04, 2000
Posts: 175
Shalini, a static method can access member variables or methods only thru a reference to an object, so this is perfectly legal and makes sense as well.
HTH
Shashi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using static class