Class cannot be applied to given types


#1



Learning Java Using Methods 2 Exercise 11
Code keeps throwing this error but mine seems the same as the example where did I go wrong?


Dog.java:30: error: method getAge in class Dog cannot be applied to given types;
spike.getAge(5);
^
required: no arguments
found: int
reason: actual and formal argument lists differ in length
1 error


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(3);
    spike.bark();
    spike.run(10);
    
    int spikeAge = spike.getAge();
    spike.getAge(5);
    System.out.println(spikeAge);
	}
}


#2

Edit: You need to put the int in front of your spike.getAge(5); Meaning that it should look like

int spikeAge = spike.getAge();
spike.getAge(int 5);

P.S. I believe some of them HAVE to give you an error, because they're teaching different keywords and such as it goes on.

public static void main(String[] args) {

Dog spike = new Dog(5);
spike.bark();
spike.run(7000);
spike.getAge(int 5)

int spikeAge = spike.getAge();
System.out.println(spikeAge);

#3

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