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
Pooja Maurya
Level 5
Mumbai
  • 05.07.2019
  • 1078views
  • 3comments

can't understand the problem

Question about the task Where does a Person come from?
Java Syntax,  Level 2,  Lesson 2
Under discussion


In the Person class, declare the following variables: String name, int age, int weight, int money.
In the main method, create a Person object and store a reference to it in the variable person.

Hint: Use the following construct to create a Person object and assign a reference to that object to the variable person:
VariableType variableName = new TypeOfObjectBeingCreated();

Requirements:
  • In the Person class, declare a String variable called name.
  • In the Person class, declare an int variable called age.
  • In the Person class, declare an int variable called weight.
  • In the Person class, declare an int variable called money.
  • In the main method, create a Person object and immediately assign a reference to it to the variable person.
  • Five variables must be declared.
package com.codegym.task.task02.task0202; /* Where does a Person come from? */ public class Solution { public static void main(String[] args) { Person Person=new Person(); //write your code here } public static class Person { String name; int age, weight,money;//write your code here } }
0
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Ali
Level 2 , Bolton, United Kingdom
9 January 2020, 20:49
When you create a "Person" object, you can't name it "Person". Java is case-sensitive language, so you can name it: 'person'. Solution is: Person person = new Person();
0
Dajana Dala
Level 2 , Preston, United Kingdom
16 February 2020, 23:26
Very useful, thank you!
0
Nithin
Level 35 , Hyderabad, India
5 July 2019, 03:52
you need to assign the created object to "person" variable not "Person". check line 9
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.