8. Methods 1

I need help,

I dont get the Exercice Add a method called bark to the Dog class by typing:

    class Dog{
      int age;
    	public Dog(int dogsAge) {
        age = dogsAge;
      public void bark() {
    	public static void main(String[] args) {
        Dog spike = new Dog(7);

This is the code i got from the Website he sais its the right but when i press run it s sais wrong

I need Help!

What does it say is wrong?

Look at where your class delimiters are. You have closed the entire class including the public static void main in one declaration. Any java interpreter will spit an error.

Could you explain exactly how i can resolve the problem @dondabreraozemail_co

Did you edit your original entry ? I thought I saw an extra } when I looked at it the first time

Ok I had some time to get back to this issue. There is nothing wrong with your code as you have it now. I thought I saw an extra } bracket previously. May have been another problem I was looking at though. Anyway, your code as it stands is good. I’ve been checking all the problems here on Java’s Netbeans IDE.
If you still can’t get it to run, one or more of the following reasons persist.

  1. The codecademy interface is a bit weird. There is a problem in the parser that checks the user input. Sometimes it will accept whitespace between things like
    public void bark () and sometimes not public void bark()
  2. What browser are you using ? I had problems with IE11 and switched to Firefox.
    Whoever programmed these lessons did’nt pay a lot of attention to letting users fix input errors.

No, but i fixed the Porblem.
Now my problime is the exercice with “pubic void run () { …}”. Dont no where to put it

This is another dog class method. Just put it directly underneath the
public void bark method.
All class methods and fields have to go before the last bit of code which is

public static void main …

This is what I complained about in an earlier post. It’s an extremely bad idea to end a class declaration with
public static void main

This should be in a separate module by itself when you start using a development environment like Netbeans or Eclipse

Thanks but to go sure could you send the code how i need to write it. Thanks!

No you need to do it yourself. How did you manage to write the code for
public void bark ?

Use it as an example

How did you fix this problem anyway ? I’m curious.

I have the same issue.

I have the same problem too

Please clarify what you need explaining

Please clarify what you need explained

having same problem, checked it several times :frowning:

I have the same issue. And it happens only on the second part of the problem.
I checked it a zillion times. I typed inside it. Perhaps its a bug?

@mariaazharkhan, @jocremustech

  1. Go here https://discuss.codecademy.com/c/learn-java/object-oriented-programming
  • Use the + New Topic button
  • Fill in the template
  • Someone will help
1 Like