Advertisement
Tankado95

Test

Sep 24th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. package tankado;
  2.  
  3. public class Counter {
  4.      
  5.             public static void main(String[]args){
  6.             Counter c=new Counter();
  7.             System.out.println(c.inc());
  8.             System.out.println(c.dec());
  9.             }
  10.    
  11.    
  12.             private int cnt;        //stato locale
  13.            
  14.             //metodo costruttore
  15.             public Counter(){
  16.                     cnt=0;
  17.                     }
  18.             // metodo
  19.             public int inc(){
  20.                     cnt++;
  21.                     return cnt;
  22.             }
  23.             //metodo
  24.             public int dec(){
  25.                     cnt--;
  26.                     return cnt;
  27.             }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement