Four mistakes

  • 8
Once again you're working on someone else's code, and once again you have to fix their mistakes. You'll need to gradually get used to this process. Luckily, this time, it's a very simple task about interfaces, with only 33 lines of code. So, no whining, just get going and fix the bugs. Hint: There are only four bugs.
You can't complete this task, because you're not signed in.
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
9 February, 11:14
I'm not sure but I think that static variables also serve to define properties common to all classes. In this case when we read "Dream.HOBBY.toString ()" you have to consider "Dream.Hobby" as: 1 (static variable HOBBY like a new object with the value of 1) and then the "toString" method increments it by another 1, so we get 2. Instead, for "new Hobby (). toString ()" creates a Hobby object which is added to index 1 (that is static) and then with the "toString ()" method is incremented by 1, so we get 3.
Timboo
Level 16, Shantou, China
3 August 2020, 05:54
why the output is 2 and 3; Someone can explain?
joe
Level 27, London, United Kingdom
20 August 2020, 07:26
Index starts as 1. When toString() is called +1 is added to index then the new value is returned.
public String toString() {
            INDEX++;
            return "" + INDEX;
        }