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
Vignesh Vickey
Level 2
Coimbatore
  • 14.12.2018
  • 1047views
  • 3comments

Person

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


0
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
EXERCISE With me
Level 2 , Delhi, India
3 January 2019, 15:43
package com.codegym.task.task02.task0202; /* Where does a Person come from?int age, int weight, int money. */ public class Solution { public static void main(String[] args) { Person person=new Person(); } public static class Person { String name; int age; int weight; int money; //write your code here } }
0
Ritwik Joshi
Level 3 , Gurgaon, India
14 December 2018, 14:36
Person is just another class in the file Solution.java. You can create your own class if you like. The task is to create a Person object and assign a reference to that object to the variable -> person. When we say - assign a reference to the variable - we simply mean to make it equal to a variable. In Java, variables are stored by reference (or address). So,
int a = 2;
means variable a is simply pointing to the location in memory where 2 is stored. It is referring to that location. When you change the value of a, you simply change the location to where a is pointing. An object is created by using the keyword new. So, to create a Person object we write:
new Person();
And now to assign a reference to the Person object - which we just created above - to a variable, we simply assign it equal to a variable of type -> Class; and which class? The same class whose object we just created i.e. Person.( Note: type can be primitive or composite. int is primitive type. Class is composite type.) So we will assign the object reference to a variable which is of type Person class. Hence,
Person person; //declaring a variable 'person' of type 'Person' class
So, combing the two code steps above, we get:
Person person = new Person(); //'Person' object created and assigned to variable 'person'
+2
Angeget
Level 22 , Potsdam, Germany
14 December 2018, 10:50
A Person is the class and you create an Object of type Person like : Person p = new Person(); p is a reference to the Person Object.
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.