public class Scope1 { public static double x; // this has what is called "class scope" // we'll study more about this later public static void main(String[] args) { double a, b, c; // local variables to main() double x, y, z; // local variables to main() // NOT the same x, y, z as in the average method // and NOT the same x as the class variable x a = 1.3; b = 2.5; c = 6.8; // arguments in a function call do NOT have to have the same // names as formal function parameters x = average(a, b, c); // local x (to main()) being used here System.out.println("average = " + x); if (x > 10) { int var1; // this variable only exists in // the body of the if statement! var1 = 20; } // end of var1's scope // var1 = 5; // would be illegal! } public static double average(double x, double y, double z) // the variables x, y, and z are LOCAL variables to this function // NOT the same as the global x. { double total; // another LOCAL variable total = x + y + z; // local x being used here return (total / 3.0); } }