Topic no 9 of object oriented


#1

`I am calling the method bark on spike object.Its showing error.


#2

please post your code


#3

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


#4

Can I have the link to the lesson?


#5

#6

this is the link


#7

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.


#8

ok thanks
actually,its not compiling


#9

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.


#10

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


#11

Yes done
Thanks a lot
no error


#12

Glad I could help. :slight_smile:


#13

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


#14

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