.
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;
}
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
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);
}