When should I use this and when to use Cat. to call the variable in Cat class?
public class Solution {
public static void main(String[] args) {
// Create 10 cats
Cat cat1 = new Cat();
Cat cat2 = new Cat();
Cat cat3 = new Cat();
Cat cat4 = new Cat();
Cat cat5 = new Cat();
Cat cat6 = new Cat();
Cat cat7 = new Cat();
Cat cat8 = new Cat();
Cat cat9 = new Cat();
Cat cat10 = new Cat();
// Display the value of the variable catCount
System.out.print(Cat.catCount);
}
public static class Cat {
// Create a static variable catCount
static public int catCount=0;
// Declare a constructor
public Cat(){
catCount++;
}
}
}