Cat relations

  • 10
  • Locked
Finished task: A cat has a name and a mother. Create a class that reflects this. Create two objects: a daughter cat and a mother. Display them on the screen. New task: Each cat has a name, a father, and a mother. Edit Cat so that it reflects these relationships. Create 6 objects: grandfather (the father's father), grandmother (the mother's mother), father, mother, son, daughter.
You can't complete this task, because you're not signed in.
Comments (17)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Devjyoti Das
Level 14 , Jind, India
12 March 2021, 01:14
why we override? how is the to string method used here exactly, no where i see it is being called
Gellert Varga
Level 23 , Szekesfehervar, Hungary
2 April 2021, 20:14
The System.out.print() command has a built-in (running invisibly) toString() method. When you start the System.out.print() command, the toString() is activated automatically. But the original toString() method in Java would write the reference of the object as an output. If you would like to see a more fiendly output, then you need to override it.
Karas Java Developer
4 September 2020, 00:16
Agree. That was quite a bit of typing.
Level 23 , Columbia, United States
20 July 2020, 03:24
This one was less difficult then some earlier ones. It's just a lot of typing.
Usha Mathivanan
Level 15 , CHENNAI, India
29 April 2020, 14:27
Hi, Anyone please help that why didn't I get the last 4 conditions correct?
Level 41
30 April 2020, 05:34
Please refer to Help section at our course.
Level 7 , unknown city, Oman
13 March 2020, 14:59
Why not it printing "else if "condition of parenti(mother) after parent(father) print.
Level 24 , Vienna, Austria
12 November 2019, 04:56
I have a question, I would like to create constructor methods, that take the name and a reference to an object as values, f.e: Cat(String name, Cat mother) {} Cat(String name , Cat father) {} here female and male objects are not the same , I solved it by turning the father constructor : Cat(Cat father, String name) {} , so I can decide which constructor to use. It works, but it is probably not the right solution, because if I had 3 different kind of objects, to reference to , it wouldn't work anymore. Could someone tell me how you solved this issue?
Level 15 , Colnbrook, United Kingdom
14 January 2020, 20:54
I hope I'm not ruining the "AHA moment", but why make it complicated? When only one parent is there, the other one is ...null. Just noticed you posted the question in November.
Level 41
13 October 2020, 16:24
yes, but 1 cat has only father and 1 cat has only mother. how do you make the differentiation and print out correctly?
kar-fai chow
Level 8 , Hong Kong, Hong Kong
19 November 2020, 04:13
instead of accepting two arguments, your constructor can accept "three arguments"! e.g. Cat(String name, String father, String mother) and if the cat has no mother? Cat sadKitty = new Cat("Sad Kitty", goodDad, null) where "goodDad" is a Cat you've already created
Kent Hervey Software Engineer/Consult at Zeal IT ConsultantsExpert
25 October 2019, 22:20
This did not seem hard to figure...but very tedious. Some passed in objects to constructor, but I did not...okay I noticed that the number of people who completed this one is about 60% of previous, so I guess many decided to move on.
carlos oliveira
Level 10 , Seattle, United States
22 April 2019, 18:55
omg!!! how flexible is Java!!! unbelievable! I really could not expect how i can twist things and its just work fine... its kind a free service objects you just need to create constructors/containers("if i can use this term") to accept them. i never seen this in any other programming language. I had to confess its took me a full day to understand it, but i got it now. just amazing!!
haet trivedi
Level 7 , Vasai-Virar, India
12 January 2019, 07:11
where am i wrong output is correct but not verifying it plzz help.
Level 41
14 January 2019, 07:12
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at
Vishwambhar Awagan
Level 8 , Pune, India
26 October 2018, 17:26
See the condition there u need to create new task..