-1
我想下面的程序該差異數數時數在Java靜態和非靜態
class Car1
{
static int count;
Car1()
{
System.out.println("Car instance has been created...");
}
Car1(int arg) {
System.out.println("Car instance has been created...");
}
Car1(double arg) {
System.out.println("Car instance has been created...");
}
Car1(int arg1, double arg2) {
System.out.println("Car instance has been crreated...");
}
{
count++;
}
}
public class MainClass10
{
public static void main(String[] args) {
System.out.println("Program Started");
new Car1(11);
new Car1(11, 12.11);
for (int i = 0; i<9; i++)
{
new Car1();
}
Car1 c1 = new Car1(11.12);
System.out.println("Total number of cars: " + c1.count);
System.out.println("Program Ended");
}
}
爲計數數輸出爲12 ,當我通過改變計數變量試試這個非靜態,則'計數數量爲1'。
任何人都可以請幫我理解這一點嗎?
你可以看看[這個](http://stackoverflow.com/questions/413898/what-does-the-static-keyword-do-in-a-class)問題的答案。 – sazzad