Class for dog


#1

public Dog(int dogsAge) {

}

Instruction: Inside of the constructor block, set the instance variable age equal to the dogsAge parameter


#2

Here's code for a car constructor:

public Car (String model, int year){
  this.model = model;
  this.year = year;
}

The this keyword references a property of the object. In a constructor, it's a property of the object being created. When, in the Car constructor, we reference this.model, we are referencing the model instance variable of the current Car object.

This method could similarly be used to reference this.age of the Dog object you're working on.


#3

Didn't work, could you please read the instruction again and if possible write the whole code for that part, I'd appreciate it!:slight_smile:


#4

I cannot provide the code for you. Study the notation provided for assigning instance variables and attempt to adapt it to your code.


#5

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