Darano

Untitled

Oct 10th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. //class vars
  2. //so every method in this class has access to it
  3. public class Hello(){
  4.     private final String NAME = "hello";
  5.     private int number = 4;
  6.  
  7.     public static void main(String... args){
  8.         System.out.println(Name);
  9.         cheese();
  10.     }
  11.     public void cheese(){
  12.         System.out.println(number);
  13.     }
  14. }
  15. ______________________________________________________________________________________
  16. //now "int number" is no class var anymore, it now is instance-var and can only be acced within the mthod it creates it
  17. //so "void cheese" would throw error
  18.  
  19. public class Hello(){
  20.     private final String NAME = "hello";
  21.  
  22.     public static void main(String... args){
  23.         int number = 4;
  24.         System.out.println(Name);
  25.         cheese();
  26.     }
  27.     public void cheese(){
  28.         System.out.println(number);
  29.     }
  30. }
  31. ______________________________________________________________________________________
Advertisement
Add Comment
Please, Sign In to add comment