Presentation is loading. Please wait.

Presentation is loading. Please wait.

Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists.

Similar presentations


Presentation on theme: "Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists."— Presentation transcript:

1

2 Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists only in that loop. A variable declared in a method exists only in that method. public static void example() { int x = 3; for (int i = 1; i <= 10; i++) { System.out.println(x); } // i no longer exists here } // x ceases to exist here x's scope i's scope

3 Parameterization parameter: A value passed to a method by its caller.
Instead of lineOf7, lineOf13, write line to draw any length. When declaring the method, we will state that it requires a parameter for the number of stars. When calling the method, we will specify how many stars to draw. main line ******* 7 ************* 13

4

5 5 2 9 2 9) Output: 2 and 4 public class ParameterMystery {
public static void main(String[] args) { int x = 9; int y = 2; int z = 5; mystery(z, y, x); mystery(y, x, z); } public static void mystery(int x, int z, int y) { System.out.println(z + " and " + (y - x)); (5 2 9) Output: 2 and 4 9 and 3 Output: 2 and 4

6 2 9 5 9 5) Output: 9 and 3 public class ParameterMystery {
public static void main(String[] args) { int x = 9; int y = 2; int z = 5; mystery(z, y, x); mystery(y, x, z); } public static void mystery(int x, int z, int y) { System.out.println(z + " and " + (y - x)); (2 9 5) Output: 2 and 4 9 and 3 Output: 9 and 3

7 Strings string: A sequence of text characters.
String <name> = "<text>"; String <name> = <expression resulting in String>; Examples: String name = "Marla Singer"; int x = 3; int y = 5; String point = "(" + x + ", " + y + ")";


Download ppt "Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists."

Similar presentations


Ads by Google