Some questions about 13 - Dog.Java

I don’t understand why we included :
-int age
-public dog(int dogsAge)
-age= dogsAge

If we don’t use them
Moreover, what does the : dog spike = new Dog(17) stand for ? and why is it included ?

It would be really greatfull if anyone can explain to me there objective
Thank you


Replace this line with your code.

<do not remove the three backticks above>

That instance variable called age is being created to hold a detail of any Dogs that we create.

That is defining the constructor that will be used every time we create a new Dog. It will be expecting a value, a parameter called dogsAge, to be sent in when a Dog is created. The parameter will be an integer.

There we are assigning the value of the parameter to our instance variable.

That is how we create a new Dog. It will be called spike and it will have a dogsAge of 17.

Thank you
It was very helpful

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.