Discuss / Java / HelloCao

HelloCao

Topic source

#1 Created at ... [Delete] [Delete and Lock User]

public class StaticTest {

public static void main(String[] args) {

// TODO Auto-generated method stub

Person.setNumber(102);

        System.out.println(Person.getNumber());

    Person peng = new Person();

    Person peng1 = new Person();

    Person peng2 = new Person();

    Person peng3 = new Person();

  System.out.println(Person.getCount()); 

}

}

 class Person {

private static int number;

public static int getNumber() {

return number;

}

private static int count;

Person(){

count=count+1;

}

    public static void setNumber(int value) {

    number = value;

}

    public static int getCount() {

    return count;

}

}


  • 1

Reply