📄 testperson.java
字号:
class Person {
private int id;
private static int total = 0;
public static int getTotalPerson() {
//id++; //illeagle
return total;
}
/*public static void setTotalPerson(int total){
this.total=total;//在static方法中不能有this
}
*/
public Person() {
total++;
id = total;
}
}
public class TestPerson {
public static void main(String[] args) {
System.out.println("Number of total is "
+Person.getTotalPerson());//没有创建对象也可以访问静态方法
Person p1 = new Person();
System.out.println( "Number of total is "
+ Person.getTotalPerson());
//Person.setTotalPerson();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -