Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static variable

 
vikas mhatre
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I know we can't access instance variable from static method.



Here a and b both are not static still we can access b but not a why?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64696
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
b is neither an instance or a static variable. It's a local variable to the method and is in scope from its declaration to the end of the method.
 
rewati raman
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a and b are not static as static key word is not used.
b is a local variable and can be accessed in main method. where as a can be accessed through out the class test.
 
vikas mhatre
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic