package com.codegym.task.task02.task0204;
/*
Family relations
*/
public class Solution {
public static void main(String[] args) {
//write your code here
Man man=new Man();
Woman woman=new Woman();
man.wife()=Man;
woman.husband()=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;
}
}
What is the error??
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Ankush Rajput
22 October 2018, 03:47
Why doing this - man.wife()=Man;
First, wife variable in Man class is of type Woman which means it should store reference to Woman object but you are trying to store Man object. Also no need of parenthesis after wife, you are only accessing a variable and not a function. It should be like - man.wife = woman or man.wife = new Woman();
I guess now you can identify another similar mistake and rectify it.
0