Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //class vars
- //so every method in this class has access to it
- public class Hello(){
- private final String NAME = "hello";
- private int number = 4;
- public static void main(String... args){
- System.out.println(Name);
- cheese();
- }
- public void cheese(){
- System.out.println(number);
- }
- }
- ______________________________________________________________________________________
- //now "int number" is no class var anymore, it now is instance-var and can only be acced within the mthod it creates it
- //so "void cheese" would throw error
- public class Hello(){
- private final String NAME = "hello";
- public static void main(String... args){
- int number = 4;
- System.out.println(Name);
- cheese();
- }
- public void cheese(){
- System.out.println(number);
- }
- }
- ______________________________________________________________________________________
Advertisement
Add Comment
Please, Sign In to add comment