How output came 5?


#1

I am not understanding how the output came 5?

class Dog {
  
  int age;

	public Dog(int dogsAge) {
    
  	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(10);
    int spikeAge=spike.getAge();
    System.out.println(spikeAge);
	}

}

output:

Woof!
Your dog ran10feet!
5


#2

5 is the age of your dog.

here:

Dog spike = new Dog(5);

you pass the age to the constructor.

then you use the getAge method to retrieve the age, store the returned result in a variable and finally print the age