+ 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
4 Antworten
+ 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()
+ 3
Your welcome👍☺
+ 2
That's because your method is static. Try to remove the static keyword or otherwise there is no difference ^^
+ 2
Thank a lot.