public class ManTest {
public static void main(String[] args) {
Man m1=new Man("张三",20,‘男‘);
m1. country="英吉利";//static修饰的成员优先于对象的创建。
Man.country="中国";//static修饰的成员随着类的加载而加载
Man m2=new Man("李四",22,‘男‘);
Man m3=new Man("王五",23,‘女‘);
System.out.println(m1);
System.out.println(m2);
System.out.println(m3);
}
}
class Man {
String name;
int age;
char sex;
static String country="中国";
public Man(String n, int a, char s) {
this.name = n;
this.age = a;
this.sex = s;
}
public String toString() {
return name + ‘\t‘ + age + ‘\t‘ + sex + ‘\t‘ + country ;
}
}
原文:https://www.cnblogs.com/syy2017/p/13933989.html