Cat and statics

  • 5
  • Locked
The sun rises. The tasks get more complicated: let's study the static keyword. This time, we need to create a static variable catCount and a constructor in the Cat class, i.e. public Cat(). Each time a cat (new Cat object) is created, increment the static variable catCount by 1. We need to create ten cats and display the value of the variable catCount on the screen.
You can't complete this task, because you're not signed in.
Comments (5)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Brandon Leirer
Level 7 , Keller, United States
12 June 2020, 23:18
Heads up guys, this one seems to be busted. If you do anything with loops or arrays the program wont take it. Just type out 10 individual objects and save yourself four hours.
Alex Vypirailenko Java Developer at Toshiba Global Comme
13 June 2020, 07:09
You CAN use loops.
Level 23 , Columbia, United States
19 July 2020, 20:10
Just used a for loop to create 10 objects. It worked.
Level 7 , Easton, United States
21 August 2020, 00:26
How do you use a loop to create 10 objects? Initially I had
for(int i = 0; i < 11; i++) {
Cat cat = new Cat();
But that was incorrect
Level 41
21 August 2020, 06:00
Try to run this code:
for(int i = 0; i < 11; i++) {
Cat cat = new Cat();
and count how many times the loop has worked