Answers for "what is scope in java"

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
0

what is method in java

Method is a collection of statements
which returns a value upon its execution.
  Method have a return and the method's name may or not be same as the class
name.
Method is invoked explicitly.
Method is not provided by compiler in any case.
Methods are inherited by child classes.
Posted by: Guest on December-05-2020
-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