What are the different scopes for java variables?

Started by chinmay.sahoo, 04-02-2016, 04:59:03

Previous topic - Next topic

chinmay.sahooTopic starter

The different scopes for java variables are as follows:-
  Local
  Instance
  Static


TomClarke

Yes, you are right! There are three types of scopes.
1. Instance - these are typical object level variables, they are initialized to default values at the time of creation of object, and remain accessible as long as the object accessible;
2. Local - these are the variables thta are defined within a method. They remain accessible only during the course of method excecution. When the method finishes execution, these variables fall out of scope.
3. Static - these are the class level variables. They are initialized when the class is loaded in JVM for the first time and remain these as long as the class remains loaded. They are not tied to any particular object instance.