what are the different scopes for java


What are the different scopes for Java variables?

The scope of a Java variable is explained by the context in which the variable is declared. Therefore a java variable can have one of the three scopes at any given point in time.

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 that are explained within a method. They remain accessible only during the course of method implemention. 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 there as long as the class remains loaded. They are not tied to any exacting object instance.

 

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: what are the different scopes for java
Reference No:- TGS0311001

Expected delivery within 24 Hours