CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Start learning now
  • All questions
Laura
Level 7
Lübeck
  • 08.09.2020
  • 516views
  • 8comments

Compiler mistake

Question about the task A programmer creates a person
Java Syntax,  Level 5,  Lesson 7
Under discussion

Create the Person class. A person should have a String name and int age.
Add the initialize(String name, int age) method where you will initialize the variables name and age.
In the main method, create a Person object and store a reference to it in the variable person.
Call the initialize method with any values.

Requirements:
  • The Solution class must contain the Person class.
  • The Person class must have a String variable name.
  • The Person class must have an int variable age.
  • The Person class must have an initialize method that takes a name and age as arguments, and initializes the corresponding instance variables.
  • You need to create a Person object and put a reference to it in the variable person.
  • You must call the initialize method on the created object and pass some arguments to it.
package com.codegym.task.task05.task0514; /* A programmer creates a person */ public class Solution { public static void main(String[] args) { Person person = new Person(); person.initialize("Peter", 17); } static class Person { String name; int age; } public void intialize(String name, int age) { this.name = name; this.age = age; } }
0
Comments (8)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Mateusz
Level 29 , Poland
9 September 2020, 07:27
First of all, there's a typo in "initialize" ;) Secondly the initialize method should be in the Person class
+1
Laura
Level 7 , Lübeck, Deutschland
9 September 2020, 14:49
Thank u, that helped me! :)
0
Mateusz
Level 29 , Poland
9 September 2020, 15:53
I'm glad :) BTW Lübeck is such a lovely city!
0
Laura
Level 7 , Lübeck, Deutschland
9 September 2020, 18:28
Unfortunately I still have one more problem :D maybe u can solve this with me too. wow, do u know Lübeck? That's amazing! And here is my recently code if u need it:
0
Misiu
Level 41 , Gdansk, Poland
9 September 2020, 18:57
The method name should be: initialize (in-i-tialize)
0
Misiu
Level 41 , Gdansk, Poland
8 September 2020, 17:57
Move } from line 17 to line 21. Check method name in line 18.
+1
Laura
Level 7 , Lübeck, Deutschland
8 September 2020, 19:06
Mmm, so should I remove the "void", too?
0
Misiu
Level 41 , Gdansk, Poland
8 September 2020, 19:09
No. This is not a constructor.
0
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.