Classes: Constructor Parameters


#1

I am on part 5 of the OOP java. The task says :

“Add an int parameter called dogsAge in between the parentheses of the Dog() constructor.”

So my code is:

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

	public static void main(String[] args) {

	}
}

But it says this is wrong and it gives the error:

“Did you add the dogsAge parameter to the constructor?”

I do not understand what is wrong.


#2

Assign the parameter to the variable, not the other way around.

age = dogsAge;

#3

It still gives my the same error


#4

https://www.codecademy.com/courses/learn-java/lessons/object-oriented-programming/exercises/classes-constructor-parameters

Try writing it without a space before the parameter list…

public Dog(int dogsAge)

#5

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