Some questions about 13 - Dog.Java


#1

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 ?

https://www.codecademy.com/courses/learn-java/lessons/object-oriented-programming/exercises/using-methods-2?action=lesson_resume&link_content_target=interstitial_lesson

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


Replace this line with your code.


#2

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.


#3

Thank you
It was very helpful


#4

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