• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding static

 
santhosh kumar vk
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have one doubt that is in static method we can not use non static variable then how it is possible in public static void main(String args[]) can you explain





Thanking you.
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Santhosh:

It isn't possible in a main() method, either. However, you can create a local instance like this:

Running the main() method should print out 'bar'.

John.
 
pankaj vijay
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in static method we cann't access instance(non static) variables. but when you are in static method you can not declare static variable BUT you can declare local variable that will be non static. As static variable belongs to class not to method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic