• Post Reply Bookmark Topic Watch Topic
  • New Topic

Static  RSS feed

 
shruti patel
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21052
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!