class Test1{
public int i;
public char c;
public static int x=10;//static的成员变量
public Test1(int i,char c){
this.i=i;
this.c=c;
}
}
public class Test{
public static void main(String[] args) {
Test1 test1 = new Test1(5,'a');
Test1 test2 = new Test1(5,'b');
System.out.println("test1-"+test1.i+test1.c+test1.x);
System.out.println("test2-"+test2.i+test2.c+test2.x);
}
}
Java--编写一个程序,展示无论你创建了某个特定类的多少个对象,这个类的某个特定的static成员变量只有一个属性。
最新推荐文章于 2020-06-08 00:54:07 发布