+ 1

Calling method from another class in java.

I cant find out the difference of calling the method of another class. https://code.sololearn.com/cKvHD5oxYBYP/?ref=app

16th Feb 2018, 7:17 AM
DarkDeveloper
DarkDeveloper - avatar
4 Answers
+ 7
If you want to call a method you should create object first. Then type object name*.method name* - dog.bark(); to call it. But we can also call the method without creating object. You don't need to create new object for calling method if it is static and you can acces the method with class name*.method name*. In your case, bark method is static so it can be called with classname.methodname - Animal.bark()
16th Feb 2018, 7:39 AM
Sad
Sad - avatar
+ 3
Your welcome👍â˜ș
16th Feb 2018, 7:44 AM
Sad
Sad - avatar
+ 2
That's because your method is static. Try to remove the static keyword or otherwise there is no difference ^^
16th Feb 2018, 7:33 AM
Chrizzhigh
Chrizzhigh - avatar
+ 2
Thank a lot.
16th Feb 2018, 7:44 AM
DarkDeveloper
DarkDeveloper - avatar