Adding class constructor Dog


#1

Can someone tell me where to add it? Thanks


#2

Please point out exactly which instruction that you are stuck on.


#3

I thought I was following the directions correctly. I may be wrong, but its my understanding that a constructor class allows us to create a subset of instructions that pertain to the main class. So my code looks something like this, but I am getting an error...What am I doing wrong?

class Dog{

public Dog(){

}
//The class constructor for the Car class
public static void main(String[] args) {

}
}


#4

Did you figure this out? I cant figure it out. Going off the example code throws an error.


#5

I tried this:

class Dog {

//public static void main(string[age, height] args) {

public Dog() {
}
}


#6

Turns out its the following:

class Dog{

public Dog() {

}

public static void main(String[] args) {

}

}


#7

class Dog{

public Dog() {

}

public static void main(String[] args) {

}

}


#8

Your suggestion worked. Thanks!


#9

Next time, if you ever get stuck, you can hit the run button a few times and eventually it will offer up the code.


#10

exactly. If you make it look like the example, it dings you. Frustrating for me.


#11

You need to read up on java classes. There is no such thing as a constructor class. Your concept of why you need a constructor is simply wrong.
Constructor is part of a class declaration. It lets the interpreter initialize the object (ie, object is an instance of the class )
A class is an abstract template.
It does not exist in a computers memory until the program instantiates it.
If you really want to learn java do yourself a favour and look up a good java website that explains this.
The Sun Oracle java pages are the best place to start.


#12

The constructor definition (ie public Dog() { .... ) needs to start on line 3 !
This is just a quirk of the code checking; not a java thing. So putting whitespace or a comment above the constructor throws up the error message 'have you added a constructor?' even when the code for the constructor definition is correct.


#13

Wow... I wish I looked at this forum an hour ago.. I was losing it.. lol.. You are absolutely correct it has to be put on line 3 to work.. I had it right all along.. just on the wrong line.. in which I would have never guessed would have made a difference...

Thanks alot!


#14

:grinning: Cool line number 3 is working without an error message. But honestly, don't you think it only fair to put a valid code anywhere? Or maybe we are beginner so code academy wants us to be systematic coder lol( It might not be a bug!) :grin:


#15

thanks .was stuck from yesterday at the same point.