Java -практика использования

       

Статическая переменная



Листинг 2.3. Статическая переменная

class Automobile {

private static int number; 

   Automobile(){ 



      number++;

      System.out.println("From Automobile constructor:"+ 

                         " number = "+number);

   }

}

public class AutomobiieTest{

   public static void main(String[] args){

   Automobile lada2105    = new Automobile(), 

              fordScorpio = new Automobile(),

              oka         = new Automobile!);

   } 

}

Получаем результат, показанный на Рисунок 2.2.



Содержание раздела