class Car {
static int frogCount = 0; // Declare and initialize static variable
public Car() {
frogCount += 1; // Modify the value in the constructor
}
}
public class MainClass {
public static void main (String [] args) {
new Car();
new Car();
new Car();
System.out.print("frogCount:"+Car.frogCount); //Access static variable
}
}
|