java variable scope

java variable scope

#java #variable #scope

//
public class main {

public static void main(string[] args) {

//local = declared inside a method
// visible only to that method

//global = declared outside a method, but within a class
// visible to all parts of a class

diceroller diceroller = new diceroller();

}
}
//
import java.util.random;

public class diceroller {

random random;
int number;

diceroller(){
random = new random();
roll();
}

void roll() {
number = random.nextint(6)+1;
system.out.println(number);
}
}
//

java variable scope