Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Liutauras Vilda
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Devaka Cooray
Paul Clapham
Saloon Keepers:
Scott Selikoff
Tim Holloway
Piet Souris
Mikalai Zaikin
Frits Walraven
Bartenders:
Stephan van Hulst
Carey Brown
Forum:
Beginning Java
static variable
vikas mhatre
Greenhorn
Posts: 26
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
As I know we can't access instance variable from static method.
class Test { int a=10; public static void main(String[] args) { System.out.println (a); int b = 20; System.out.println (b); } }
Here a and b both are not static still we can access b but not a why?
Bear Bibeault
Sheriff
Posts: 67752
173
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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.
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
rewati raman
Ranch Hand
Posts: 62
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks Bear
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
static : Bug in K&B P-145
Doubt: Main method
confusion with static variable....
Method question
Overridding Pls Explain this code
More...