This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Static Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static" Watch "Static" New topic
Author

Static

shruti patel
Ranch Hand

Joined: Mar 10, 2008
Posts: 52
class A{
static int i=20;
int j=10;
}

If i will create 10 objects of the above class.
then how many i's and j'S will be available?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

If a field is marked as static, there is just one value for all instances of the class. Otherwise, there is one value for each instance.

So if you create 10 objects (instances), there will be 1 i and 10 j's.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Rob Prime:
So if you create 10 objects (instances), there will be 1 i and 10 j's.


hi Rb prime good explanation,

where these i and j are store?... and how these copies are created? please can you explain me?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38398
    
  23
Whenever I want that sort of information, I go to the BCEL Manual.

Not at all easy to read, but it should explain your question.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Thanks Campbell
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static