I am learning Java using Codecademy. I am trying to write code that would make an object (in this case a 3 year old dog named Spike) to run on on n legs where n = age. I tried "brute force debugging", but that didn't work. How should I change the line "how to change this" to make the code work?
class Dog {
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 static void main(String[] args) {
Dog spike = new Dog(3);
spike.bark();
spike.run(this.age); // How to change this?
}
}
agein the constructor, it's only visible within the constructor. This is an example ofscope.