11/13 instruction 2


11. Using Methods: II

The question is not clear. I have no idea what it is asking of me. http://prntscr.com/c7ki9f

class Dog {
  int age;

	public Dog(int dogsAge) {
  	age = dogsAge;
  public void bark() {
  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);




Hey there.

Remember the instance variable age? And remember how when we created the Dog object we passed an age into the constructor parameters to set that age?

Dog spike = new Dog(5);

Well what this question is asking is, call the method in our Dog class that returns the age for the dog we set previously and store it in a brand new variable called spikeAge. When we call spike.getAge() this is going to return an int value of 5.

So in theory if we create that new variable and assign it to spike.getAge() we'll satisfy the requirements.

It should look like this:

int spikeAge = spike.getAge(); // gets the spike objects age variable and assigns it to spikeAge

I hope that is more clear now.


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