Answers for "scope in java explained"

1

scope java

public class example{
	// A variable here is visible through the entire class. Every single method
    // in this program can see and modify the variable
    
	public static void main(String[] args){
    	// A variable here is only defined in main, therefore no other methods 
        // can access or modify the variable
        
    for(){
    	// A variable here is only visible in the for loop, and no other part
        // of the program may access this variable
    }// for
    
    }// main
}// class

As seen by the examples above, where you put the variable will matter as to 
what can access, view and modify the variable, which is defined as scope
Posted by: Guest on October-18-2021
-1

Variable scope in Java

public class Main {
  public static void main(String[] args) {

    // Code here CANNOT use x

    int x = 100;

    // Code here can use x
    System.out.println(x);
  }
}
Posted by: Guest on October-19-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language