This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread 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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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: 20132
    
  30

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 - OCEJPAD 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: 44545
    
  34
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
 
It's not a secret anymore!