Friday, 13 September 2013

Static members in java

class staticdemo{
int objno;
static int objcnt;

void hitcount(){
objno = ++objcnt;
}

void showhits(){
System.out.println("This page has been hit for :"+objcnt);
}

void showposition(){
System.out.println("client"+objno +"/" +objcnt);
}

}

public class Static {

    public static void main(String[] args) {
    staticdemo s = new staticdemo();
    staticdemo t = new staticdemo();
    staticdemo v = new staticdemo();
  
    s.hitcount();
    t.hitcount();
    v.hitcount();
  
    v.showhits();
  
    s.showposition();
    t.showposition();
    v.showposition();
  
    }
}