Advertisement
pexea12

Static Var

Jul 12th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. public Person {
  2.     public static int staticVar = 0;
  3.     public static int var = 0;
  4.  
  5.     Person() {
  6.        staticVar++;
  7.        var++;
  8.     }
  9.  
  10.     public static int main(String[] args) {
  11.         Person p1 = new Person();
  12.         Person p2 = new Person();
  13.  
  14.         System.out.println(p1.staticVar + " " + p1.var);
  15.         System.out.println(p2.staticVar + " " + p2.var);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement