whats wrong , please tell me. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
4th Nov 2017, 7:50 AM
Emilio Pozo
Emilio Pozo - avatar
6 Answers
+ 9
It'll be good to have another field called name. Something like this? https://code.sololearn.com/ciX9y63IpY75/?ref=app
4th Nov 2017, 8:05 AM
Shamima Yasmin
Shamima Yasmin - avatar
+ 8
this.Animali = eats; What is Animali here? Also, method return type cannot be void and String together.
4th Nov 2017, 7:55 AM
Shamima Yasmin
Shamima Yasmin - avatar
+ 6
1. When we use the keyword "this", it's expected to have a data field after that. Like this.name, this.legs etc. are correct. But since Animali is not a field, this.Animali will cause error. 2. conflicting return type 3. You passed the String "Dog" as method argument and set it as Animali which doesn't exist. I've re-written your code using Animali. But it's always a good practice to set data fields using setter or constructor. https://code.sololearn.com/cvVOwp09gDgW/?ref=app
4th Nov 2017, 8:50 AM
Shamima Yasmin
Shamima Yasmin - avatar
+ 2
thank you, thats what i wanted to do, but what was wrong in my code?
4th Nov 2017, 8:08 AM
Emilio Pozo
Emilio Pozo - avatar
+ 1
i just tried to figured out the error, changing the name several times. i want to animal gets the string dog in main and then prints with ( string + "eats")
4th Nov 2017, 7:58 AM
Emilio Pozo
Emilio Pozo - avatar
+ 1
thanks 😊😊
4th Nov 2017, 8:55 AM
Emilio Pozo
Emilio Pozo - avatar