• 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

Using static class

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I wonder how we use static classes. Do we instantiate them? What exactly are they differing from regular classes?
Thanks!
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you are right and my wordings were confusing
I have edited my post to make it clearer
Thanks!
Ajith
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic