• + 0 comments

    There is an issue with the testcases for this program

    public class InstanceOFTutorial{

    static String count(ArrayList mylist){ int a = 0,b = 0,c = 0; for(int i = 0; i < mylist.size(); i++){ Object element=mylist.get(i); if(element instanceof Student) a++; if(element instanceof Rockstar) b++; if(element instanceof Hacker) c++;

      }
      String ret = Integer.toString(a)+" "+ Integer.toString(b)+" "+ Integer.toString(c);
      return ret;
    

    }

    This is the code I have written, which passes the testcase, but if I add {} after the if condition as shown below, or try to add any comment, the testcase will fail, which should not happen

    if(element instanceof Student) { a++; } //Or if you add any comment like this anywhere in the code, it will fail