Help

.
Inside of main, use the Dog constructor to create a Dog object and assign it to the variable spike. Make sure that you specify the required int parameter age…?

class Dog {

int age;
public Dog(int dogsAge)
{
age = dogsAge;
}

public static void main(String[] args) 

{
Dog spike = new Dog ();
}

}

According to the constructor of the Dog class. Every Dog object that is created must have one argument passed to it(and it musty be of type int) , **the age**. So when you write this on this line

Dog spike = new Dog ();

it is incorrect because the compiler wants to see an argument passed to this instance of dog.it should rather be

Dog spike = new Dog(5); // you can pass any int argument

Thanks for your reply its still giving me an error …;(
This is what i put in .

Dog spike = new Dog (15);

take away the space between Dog and (15) for example ( Dog spike = new Dog(15); )

Thanks that helped :slight_smile:

A post was split to a new topic: I am having error after entering ; Dog spike = new Dog(7);

Inside of main, use the Dog constructor to create a Dog object and assign it to the variable spike. Make sure that you specify the required int parameter age…?

Why isn’t this working?

class Dog {

int age;
public Dog(int dogsAge)
{
age = dogsAge;
}
public static void main(String arg)
{
Dog spike = new Dog(5);
}

}