Stuck on 4.13


I'm being asked to insert an instance variable in the class Dog. I did so. I had to keep a main method in the program for it to run. I've inserted the instance variable variable "int age;" before the main method, in the body of the main method, and after the main method (but before the Dog constructor). I'm still getting an error message. Can someone explain to me what is wrong?

class Dog{

public static void main(String[] args) {


int age;

public Dog(){




Perhaps the error message says what's wrong? Almost no matter what it's a huge hint to what's wrong.
You say that you had to keep the main method, was there a reason to remove it? It's probably best not to remove anything unless it's part of the instructions to do so.


The error message says "Did you create an instance variable called 'age'? Place it inside the class, but before the Dog constructor."

Which is what I did. I placed "int age;" within the Dog class's braces, but before the Dog constructor. I tried placing it before the main method, in the main method and then after the main method, but all three attempts still give me the same error message.

I've attempted this exercise through Chrome, Firefox and Internet Explorer. Still getting the same error message.


Yeah I think the main method's position is interfering - I'm guessing that it was located below the constructor, and then you moved it, and now you've got a situation that the exercise author did not anticipate.


If I recall correctly, the main method wasn't automatically place in the code, I had to type it out myself. But I didn't think to place it past the Dog constructor. I just cut and pasted it below the entire Dog constructor body and now I can proceed to the next step.

Thank you for the info.