0

Method confusion

In the previous lessons, it was shown that a method could be called without creating an object. Now this is saying to create a new dog object in the Animal class to call dog.bark(). But can can't just call bark() as shown before? Thanks for the help!

9th Feb 2017, 10:34 PM
Sathvik Kuthuru
Sathvik Kuthuru - avatar
4 Answers
+ 3
Method must be static to be called without instance.
9th Feb 2017, 10:36 PM
Zilvinas Steckevicius
Zilvinas Steckevicius - avatar
+ 1
If method doesn't use any of its class non-static fields, then you should mark it static, otherwise it can't be static.
9th Feb 2017, 10:44 PM
Zilvinas Steckevicius
Zilvinas Steckevicius - avatar
0
Oh thanks Zilvinas! Also, can you tell me when it is more beneficial to use static and when not to? Thanks a bunch!
9th Feb 2017, 10:42 PM
Sathvik Kuthuru
Sathvik Kuthuru - avatar
0
solo usa un metodo Static() :v
9th Feb 2017, 10:48 PM
Edgar Quintero
Edgar Quintero - avatar