Object-Oriented Java 9 Using Methods 1


#1



Help me! I dont know where I wrong??

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


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.


#2

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.


#3

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