I tried different ways to solve the task but I always got a weird output. When I hit the validation button, I passed the task -.-
Is still don't understand the output:
I created 4 cats and 3 dogs (=7) and put them into a set. After that I deleted the 4 cats, so there should be just 3 objects!?
But in the output I see 10 objects(4 Cats, 6 Dogs) which doesn't make any sense for me.
com.codegym.task.task08.task0820.Solution$Cat@23fc625e
com.codegym.task.task08.task0820.Solution$Dog@63961c42
com.codegym.task.task08.task0820.Solution$Dog@85ede7b
com.codegym.task.task08.task0820.Solution$Cat@4f023edb
com.codegym.task.task08.task0820.Solution$Dog@5674cd4d
com.codegym.task.task08.task0820.Solution$Cat@3f99bd52
com.codegym.task.task08.task0820.Solution$Cat@3a71f4dd
com.codegym.task.task08.task0820.Solution$Dog@63961c42
com.codegym.task.task08.task0820.Solution$Dog@85ede7b
com.codegym.task.task08.task0820.Solution$Dog@5674cd4d
Can someone help me to understand?
Thanks in advance :)
confusing output
Resolved
Comments (6)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
22 January 2021, 14:16
To answer your question we would have to see your code.
0
Guadalupe Gagnon
22 January 2021, 16:56solution
So, the good new is the code works exactly as intended. Here is what you are noticing:
If you look at your output, the first 7 are a mix of Cat and Dog objects from the first printPets() method call, then the last 3 are all Dog() objects from the second printPets() method. So you are seeing the result of both the printPets() methods being called. The computer works so fast that it happens instantly and looks like one output. You could add this into the code between those lines to separate the final output:
You won't get in trouble for posting the solution, they may delete your comment at the worst, however you can modify your comment to only show the main method if you want to make it more acceptable. I personally don't like seeing the solution to tasks posted publicly, it doesn't help people learn programming by just copying other people's solution; but with that being said, honestly, the people that just copy other people's solutions are going to do so no matter what. It really matters not either way. +4
Jurij Thmsn
22 January 2021, 19:33
Aah I see. Now I feel stupid for asking ;)
Thanks again a lot Guadalupe! You are really helping me to understand! :)
0
Jurij Thmsn
22 January 2021, 19:36
Sometimes when I stare on the code for too long, some lines get invisible :D
0
Guadalupe Gagnon
22 January 2021, 19:40
Don't feel that you are any worse than anyone else first learning, we all go through the learning curve. I know all about not seeing the very obvious. Even now, I can sit at my code for over an hour trying to find what I think is a huge problem in my code. When I actually find the issue it ends up being something small like I was off by one (a very common error).
There is a saying in computer programming: "The 3 most common errors are 1) naming errors; and 2) off by one errors".
+2
Jurij Thmsn
23 January 2021, 09:18
That one made me laugh :D
That makes me feel better ;) I'll just keep going and going. CodeGym definitely helps me to train my frustration tolerance, which is a good thing i guess.
Thanks again !!! :)
0