• 13
  • Locked
Implement the getTwoSolutions method, which should return an array of 2 instances of the Solution class. For each instance of the Solution class, initialize the innerClasses field with two values. All data must be initialized only in the getTwoSolutions method.
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
Dave Andrea
Level 41 , Canada
20 June 2020, 21:59
I honestly have no idea what this task is asking us to do. I passed it by copying what others did in the help section, but I would never have arrived at that by reading only the instructions.
Level 41 , Madrid, Spain
26 January 2021, 09:03
I guess this exercise reinforces the idea that you can't create an instance of an inner class without previously instantiating the outer class. In addition to that, it shows you how to access the constructor of the inner class (new InnerClass()) as a method of the outer class:
InnerClass innerClassObject = new OuterClass().new InnerClass();
Justin Smith
Level 39 , Greenfield, USA, United States
1 January 2022, 00:42
I understand the code involved for this task, but it seems like bad code design to me. I know these tasks are simplified for the purpose of teaching coding, but I have a hard time imagining a situation where this type of code would be the best way to solve the problem. It seems like there should be better options than this. Wouldn't it be better to have a Solution() constructor that initializes the innerClasses field? That way, the getTwoSolutions method could just create the new Solution objects.