Thread: Static fields
View Single Post
  #1 (permalink)  
Old 04-18-2008, 08:09 AM
Eranga's Avatar
Eranga Eranga is online now
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,396
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Static fields
Hi all,

All of you know about static fields(class variable). I just want to see your opinion on one thing, just make your comment here, not a question at all.

Code:
public class MyClass { static int myNumber = 0; // class variable // do the rest of processing of MyClass }
In the above class I've initialized a static field. I can refer that in two ways.
  1. Using the class name
  2. Using an object reference

Something like this.

Code:
MyClass.myNumber myClassObject.myNumber
Actually even I courage to use the first way to do this, because the variable is a class level(I mean class variable) and easy to differ it from others.

But some people says that, the second way is the easiest because it is common to refer locals.

What is your comments on it.

Eanga
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on July 13, 2008)
Reply With Quote
Sponsored Links