• Post Reply Bookmark Topic Watch Topic
  • New Topic

Static  RSS feed

 
Krishna Tota
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
When we import a class from a package we need to create an object for that class.when we create an object only instance variables are present on that.what about the static variables if we want.

Please explain in brief.

Thanks,
Krishna
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't understand the question, I am afraid.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any object that you create has access to the static variables of the class. But even if you don't create any objects at all, you can use the public static variables in the class.

Does that answer your question?
 
sudipto shekhar
Ranch Hand
Posts: 826
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The static variables and methods of the class can be accessed without creating an object of the class as they do not depend on any instance of the class.Static variable is single for a class whereas instance variables is for instance of the class.

using variable MyClass.java static int i

MyClass.i=1;

using method MyClass.java public static void display())

MyClass.display();


with regards,

S.Shekhar.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!