1 for (int i = 0; i < 10; i++) 2 { 3 student.b++;//静态字段若不赋值,默认为1; 4 new student().a++;//引用类型变量定义后,必须使用new关键字创建对象 才能后才能使用 5 Console.WriteLine(student.b + " " + new student().a); 6 } 7 Console.WriteLine(new student().shu()); 8 9
10 11 class student12 {13 public int a;14 public static int b;//静态成员不随着造对象初始化。类的静态方法只能访问 静态字段15 public int hanshu()16 {17 return a + b;//类的字段可以被实例方法直接调用18 }19 public int shu()20 {21 return hanshu();//位于同一类中的普通方法可以相互调用22 }23 }
新闻热点
疑难解答