Why public dog() placed after declaring int age?


why the class characteristic ie public dog() declared after declaring instance of age ?
Why is it not placed before ?


From what I know it doesn't matter. But it seems like it matters for the testing of the exercise somehow so better stick to what the instructions tell you as otherwise the code checking might go wrong. It also helps if you keep a little struture in your class as you have to deal with variables functions and also with private, public and protected stuff as well.


Its not called the class characteristic. It is the class constructor. All objects need a constructor to work. Java automatically puts a constructor into the code if its not done by the program. You always place the constructor after declaring any preliminary class variables. Mostly, your preliminary class variables are private variables and can only be set by the constructor in the first instance or, after declaring an instantiation of the class, that is by creating an object, you can then set your private variables thru the class methods.