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
Ashok Rai
Level 3
Kathmandu
  • 03.12.2018
  • 1039views
  • 3comments

what to do next im having trouble i couldnt understand what to do next?

Question about the task Family relations
Java Syntax,  Level 2,  Lesson 2
Under discussion


In the main method, create a Man object and save a reference to it in the variable man.
Also, create a Woman object and save a reference to it in the variable woman.

Hint: Use the following construct to create a Woman object and assign a reference to that object to the variable woman:
VariableType variableName = new TypeOfObjectBeingCreated();
Save a reference to the previously created Woman object in man.wife.
Save a reference to the previously created Man object in woman.husband (Hint: woman.husband = man).

Requirements:
  • In the main method, create a Man object and save a reference to it in the variable man.
  • In the main method, create a Woman object and save a reference to it in the variable woman.
  • In the main method, store a reference to the previously created Woman object in man.wife.
  • In the main method, store a reference to the previously created Man object in woman.husband.
  • The Man class must have 3 variables.
  • The Woman class must have 3 variables.
package com.codegym.task.task02.task0204; /* Family relations */ public class Solution { public static void main(String[] args) { //write your code her Man man = new Man(); Woman woman = new Woman(); } public static class Man { public int age; public int height; public Woman wife; } public static class Woman { public int age; public int height; public Man husband; } }
0
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Ali
Level 2 , Bolton, United Kingdom
9 January 2020, 23:06
Man man = new Man();
Woman woman = new Woman();
man.wife = woman;
woman.husband = man;
0
Dx
Level 3 , Chittagong, Bangladesh
17 November 2019, 09:02
man.wife=woman; woman.husband=man;
0
Michael Martin
Level 19 , Arlington, United States
3 December 2018, 14:32
You completed the first two requirements. The last two want you to assign the man and woman objects to the related fields in the Man and Woman classes. For example:
man.wife = woman;
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.