/*
Cats in the Universe
*/
public class Solution {
public static void main(String[] args) {
Cat cat1 = new Cat();
cat1.count++;
Cat cat2 = new Cat();
cat2.count++;
Cat.count = cat1.count + cat2.count;
System.out.println("The cat count is " + Cat.count);
}
public static class Cat {
public static int count = 0;
Cat()
{
int count = 1;
Cat.count += count;
}
}
}
The last condition (The variable count must store the actual number of cat objects created) isn't valid.
Why?
Thanks a lot!
package com.codegym.task.task04.task0407;
/*
Cats in the Universe
*/
public class Solution {
public static void main(String[] args) {
Cat cat1 = new Cat();
cat1.count++;
Cat cat2 = new Cat();
cat2.count++;
Cat.count = cat1.count + cat2.count;
System.out.println("The cat count is " + Cat.count);
}
public static class Cat {
public static int count = 0;
Cat()
{
int count = 1;
Cat.count += count;
}
}
}