Dogs age returned as 0

Hello, I have an issue with the following excercise.

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

The age returned is 0 even though it should be 5.


class Dog {
  
  int age;

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

public void bark() {
  System.out.println("Woof!");

}
  
  public void run(int feet) {
	System.out.println("Your dog ran " + feet + " feet!");
}
  
  public int getAge() {

    return age;

}
  
	public static void main(String[] args) {
    
    Dog spike = new Dog(5);
    spike.bark();
    spike.run(15);
    int spikeAge = spike.getAge();
    System.out.println(spikeAge);

	}

}


Thank you

Never mind, the problem was in the

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

while it should be

public Dog(int dogsAge){
  
  age = dogsAge;
  
}
2 Likes

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