Topic no 9 of object oriented

please post your code

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(20);
spike.bark();
}

I m calling bark function using spike object
its showing error
i m learning java in codecademy
This is regarding OOP in java

Can I have the link to the lesson?

https://www.codecademy.com/courses/learn-java/lessons/object-oriented-programming/exercises/using-methods-1

1 Like

https://www.codecademy.com/courses/learn-java/lessons/object-oriented-programming/exercises/using-methods-1

this is the link

I can’t figure out what’s wrong, so you should reset your code, and try one more time to call the bark method on spike, inside of the main method.

ok thanks
actually,its not compiling

I figured out what’s going on,

System.out.println("Woof!");  }
                              ^
}	public static void main(String[] args) {
^

right here, you have two closing brackets, so you need to delete of one of them, and then put one at the very end of your code.

1 Like

I did that
I removed one curly bracket
Still its showing error
not compiling

Yes done
Thanks a lot
no error

1 Like

Glad I could help. :slight_smile:

ya sure
Let me introduce myself
I m akshay dharmapuri
doing btech final year

1 Like

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