Problem with getting the code to return dog's age


#1



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


Hi,

sorry to bother you but I got stuck at the object oriented excercises (linked above). I'm trying to get the code to return the dog spike's age. After several erros I arrived at a code that at least returns some values...
But it still returns age as "0", even though it should be "9" (or should it?)
I'm really new to coding, and so I'm not sure what the problem might be (or even if this is the right kind of question). Please help...?


class Dog {
int age;
	public Dog(int dogsAge) {
  dogsAge = age;
  }  
  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(9);
spike.bark();
spike.run(5);
int spikeAge = spike.getAge();
    System.out.println(spikeAge);
   
  }

}


#2

Did you try,

age = dogsAge;

?


#3

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