What's wrong with my method code?


#1



https://www.codecademy.com/en/courses/learn-java/lessons/object-oriented-programming/exercises/using-methods-1?action=resume


Did you call the bark method on the spike object? Make sure you call it inside of the main method.


class Dog{

  int age;
  
  public Dog(int dogsAge) {
      age = dogsAge;
  }

  public void bark() {
      System.out.println("Woof");
  }  

  public static void main(String[] args) {
      Dog spike = new Dog(2);
      spike.bark();
  }
}


#2

Hey @designninja33974

It looks like a small problem, not with your code, but with the lesson. If you look at your bark method, it says "Woof" when the instructions ask for "Woof!". Simple fix: Place the exclamation point inside. This should fix it. The reasoning behind this is because the lesson creator makes it look for the output of "Bark!" (with the exclamation) and it will register as the bark method not running if it isn't there. It should fix your problem. Hope this helps. Good luck. :coffee:


#3

A post was split to a new topic: Same problem


#4

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