日期:2014-05-20 浏览次数:20820 次
import java.util.*;
public class Test
{
public static void main(String[] args)
{
A[] employee = new A[3];
employee[0] = new A();
employee[1] = new A();
employee[2] = new A();
for(A e: employee)
{
System.out.println(e.a);
}
}
}
class A
{
public static int a = 0;
public A()
{
a++;
}
}
import java.util.*;
public class Test
{
public static void main(String[] args)
{
A m = new A();
System.out.println(m.a);
A n = new A();
System.out.println(n.a);
A x = new A();
System.out.println(x.a);
}
}
class A
{
public static int a = 0;
public A()
{
a++;
}
}
import java.util.*;
public class Test
{
public static void main(String[] args)
{
A[] employee = new A[3];
employee[0] = new A();//这里 a++ 的数值是 1
employee[1] = new A();//这里 a++ 的数值是 2
employee[2] = new A();//这里 a++ 的数值是 3
//最终你的 a 的数值是 3,所以下面你会打印3遍 3
for(A e: employee)
{
System.out.println(e.a);
}
}
}
class A
{
public static int a = 0;//注意:你这里的变量是 static,也就是说这个变量是“类”变量。
public A()
{
a++;
}
}
import java.util.*;
public class Test
{
public static void main(String[] args)
{
A m = new A();//这里 a++ 的数值是 1
System.out.println(m.a); //打印 1
A n = new A();//这里 a++ 的数值是 2
System.out.println(n.a);//打印 2
A x = new A();//这里 a++ 的数值是 3
System.out.println(x.a);//打印 3
}
}
class A
{
public static int a = 0;
public A()
{
a++;
}