I tried to put "3" as dog's age, but it doesn't work. Don't know why

I tried to put “3” as dog’s age, but it doesn’t work. Don’t know why.

So, I clicked Get code, and got answer 5. WHY?

Is there anyone can explain why? I am very beginner of this Java code…

Thank you~

please post your code

public static void main(String args) {

Dog Spike = new Dogs (5)

Wrong answer: Dog Spike = new Dogs (n)

Right answer: Dog Spike = new Dogs (5) Why it is 5?

5 is an arbitrary number, so perhaps something, like the instructions, is saying that 5 is the desired value. If you want it to be 3, then 5 wouldn’t be the number to use.

If you’re using n before having defined n, then you’ve created something that is impossible to execute, so it won’t.

You forgot ‘;’ after (5) ?

Maybe because you used the space bar?
Not: new Dog (5);
But: new Dog(3);


It’s not a problem with the age, its that you capitalized the name Spike when it wants spike, so this should work. I was having the same problem until i realised the Capitalization thing changed when I clicked get code.

Dog spike = new Dog(3);

to luvinliiph yes you are right Capitalizastion is important in programming.

to devsolver76125 No spacebar isnt important. every whitespace is ignored by the IDE

1 Like

thanks for the reply

Thanks for the answer, I’ve tried it a lot of times.

Funny, the built-in IDE didn’t accept my Dog spike = new Dog (2); because of the space between Dog and (2)…

I only got it right after removing the space there.

possible but shouldn’t. The problem might have been the ‘checker’ Codecademy is trying to check if you’ve written the right things so if they aren’t accepting new Dog (2) then u have to remove the space. But a common IDE shouldn’t care idk didn’t tested that.


Yeah, you’re probably right…