Object-Oriented Java 9 Using Methods 1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

Help me! I dont know where I wrong??
<Below this line, add a link to the EXACT exercise that you are stuck at.>
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(12);
spike.bark();
}
}

<In what way does your code behave incorrectly? Include ALL error messages.>
Dog.java:9: error: illegal start of expression
public void bark()
^
Dog.java:9: error: illegal start of expression
public void bark()
^
Dog.java:9: error: ‘;’ expected
public void bark()
^
3 errors

```

Replace this line with your code.

<do not remove the three backticks above>

The curly bracket in this part of code:

{
public void bark() 

should be reversed to close definition of the constructor.


And there are too many } in this code, after the bark method. Please remember that method main is part of the Dog class.

1 Like

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