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.
Cat relations
- 10
Locked
Comments (17)
- Popular
- New
- Old
You must be signed in to leave a comment
Devjyoti Das
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
0
Gellert Varga
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.
+2
Karas Java Developer
4 September 2020, 00:16
Agree. That was quite a bit of typing.
0
Petros
20 July 2020, 03:24
This one was less difficult then some earlier ones. It's just a lot of typing.
0
Usha Mathivanan
29 April 2020, 14:27
Hi, Anyone please help that why didn't I get the last 4 conditions correct?
0
Roman
30 April 2020, 05:34
Please refer to Help section at our course.
0
I.A
13 March 2020, 14:59
Why not it printing "else if "condition of parenti(mother) after parent(father) print.
0
Paul
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?
+1
Daniel
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.
+1
Andrei
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?
0
kar-fai chow
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
0
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.
0
carlos oliveira
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!!
+1
haet trivedi
12 January 2019, 07:11
where am i wrong
output is correct but not verifying it plzz help.
0
Roman
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 codegym.cc/help.
0
Vishwambhar Awagan
26 October 2018, 17:26
See the condition there u need to create new task..
0