hey guys, I have some confusion regarding the static int index in Hobby class. I am assuming this is a class variable and should increase by 1 each time hobby is being called.
That's why I think
System.out.println(Dream.HOBBY.toString()); // should be 2
System.out.println(new Hobby().INDEX); // should be 3
Any feedback would be appreciated! Thanks!
package com.codegym.task.task13.task1321;
public class Solution {
public static void main(String[] args) {
System.out.println(Dream.HOBBY.toString());
System.out.println(new Hobby().INDEX);
}
interface Desire {
}
interface Dream {
public static Hobby HOBBY = new Hobby();
}
static class Hobby implements Desire, Dream {
static int INDEX = 1;
@Override
public String toString() {
INDEX++;
return "" + INDEX;
}
}
}