CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Question
  • Reviews
  • About us
Start
Start learning
Start learning now
  • All questions
Michal
Level 26
Lodz
  • 03.06.2020
  • 302views
  • 2comments

Why this fails? In InteliJ work fine

Question about the task Inner
Java Multithreading,  Level 3,  Lesson 4
Under discussion


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.

Requirements:
  • The Solution class must implement the getTwoSolutions method.
  • The getTwoSolutions method must be static.
  • The getTwoSolutions method must be public.
  • The getTwoSolutions method must return a Solution array filled according to the task conditions.
package com.codegym.task.task23.task2305; /* Inner */ public class Solution { public InnerClass[] innerClasses; public static class InnerClass { } public static Solution[] getTwoSolutions() { Solution[] result = new Solution[2]; result[0] = new Solution(); result[0].innerClasses[0] = new InnerClass(); result[0].innerClasses[1] = new InnerClass(); result[1] = new Solution(); result[1].innerClasses[0] = new InnerClass(); result[1].innerClasses[1] = new InnerClass(); return result; } public static void main(String[] args) { } }
0
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
dnlklnhfr
Level 30 , Karlsruhe, Germany
11 July 2020, 13:54
Well in fact your solution is correct. The only thing what happened is that your variable "innerClasses" in line 8 was changed compared to the original template code. The original code provided from CodeGym in line 8 was :
public InnerClass[] innerClasses = new InnerClass[2];
Means that only the initialization is missing in your version of the code.
0
Thomas
Level 41 , Bayreuth, Germany
11 June 2020, 10:52
You should use the innerClass field declared in line 8 instead of your variable result.
-1
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.