Created
December 10, 2010 19:06
-
-
Save kellydunn/736627 to your computer and use it in GitHub Desktop.
Rassul's Java Lessons 1 : Variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void letsLearnJava() { | |
int x = 2; | |
int y = 2; | |
int z = x + y; | |
// The println function is smart enough to wrap the int value into a String variable :) | |
System.out.println(z); // prints "4". | |
} | |
// Less redundant. You don't need the z variable. | |
public static void letsLearnJava() { | |
int x = 2; | |
int y = 2; | |
System.out.println(x + y); // prints "4" | |
} | |
// SCOPE ERROR | |
// You don't have access to variables outside of the methods you declare them in | |
public static void badScope() { | |
System.out.println(x); // Exception thrown. Java is sad :( | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment