public class Solution {
public static void main(String[] args) {
Woman woman;
woman = new Woman();
Cat cat;
cat = new Cat();
cat.owner=woman;
Dog dog;
dog = new Dog();
dog.owner=woman;
Fish fish;
fish = new Fish();
fish.owner= woman;
}
public static class Cat {
public Woman owner;
}
public static class Dog {
public Woman owner;
}
public static class Fish {
public Woman owner;
}
public static class Woman {
}
}
What wrong with code?
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Beautiful Active Dedicated
19 April 2019, 03:12
0
Don Boody
18 April 2019, 10:39
You are very close on this. You just need to swap stuff like:
Woman woman;
woman = new Woman();
for stuff like:
Woman woman = new Woman();
The way you're doing it now isn't technically incorrect (You're still creating a woman object and storing it in a variable) but what you're doing is creating and assigning a variable of type Woman on one line and then, on another line, creating an instance of Woman and assigning it to your variable. You want to do all of this one the same line.
So if you go through your code and handle the woman, fish, etc each in all one line instead of two, you'll pass the task. I think they're stopping you to reinforce the "best practice" way of handling the object creation.
0
Александр Олегович
18 April 2019, 06:44
In the main method, create Cat, Dog, Fish, and Woman objects, and store references to them in variables.
RECOMMENDATION FROM YOUR MENTOR
Be sure that a Cat object has been created and stored in a variable.
0