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.
Cat and statics
- 5
Locked
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
Brandon Leirer
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.
+3
Alex Vypirailenko Java Developer at Toshiba Global Comme
13 June 2020, 07:09
You CAN use loops.
0
Petros
19 July 2020, 20:10
Just used a for loop to create 10 objects. It worked.
0
Ashleigh
21 August 2020, 00:26
How do you use a loop to create 10 objects?
Initially I had
But that was incorrect +1
Roman
21 August 2020, 06:00
Try to run this code:
and count how many times the loop has worked +3