I have attempted to play with the example and it doesn't work? Why?


So I took the example and added in dogs name so that I could have it say "His name is X" but it returns the error:

// Dog.java:34: error: cannot find symbol
symbol: method name(int)
location: variable spike of type Dog
1 errorr //

Why does it return this error when my name/who method is written identically to the examples?

Thank you in advance for helping :slightly_smiling:


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(9);

int spikeAge = spike.getAge();
System.out.println("He is " + spikeAge + " years old");




There is no method called name. The line is invalid.


Apologies for the post I have sorted it out now.

Thank you for responding