class Member {
static int classVar;
int instanceVar;
static void setClassVar( int i ) {
classVar = i;
}
static int getClassVar() {
return classVar;
}
void setInstanceVar( int i ) {
classVar = i;
instanceVar = i;
}
int getInstanceVar() {
return instanceVar;
}
public class MemberTest {
public static void main( String[] args ) { //提示 内部类不能有静态声明,请问我该怎么改,为什么?,谢谢
Member m1 = new Member();
Member m2 = new Member();
m1.setClassVar(1);
m2.setClassVar(2);
System.out.println( "m1.classvar = " + m1.getClassVar() +
"m2.classvar = " + m2.getClassVar() );
m1.setInstanceVar(11);
m2.setInstanceVar(22);
System.out.println( "m1.Instancevar = " + m1.getInstanceVar() +
"m2.Instancevar = " + m2.getInstanceVar() );
}
}
}
[此贴子已经被作者于2006-7-16 9:49:40编辑过]