Why should I create a static method and not one that could instantiate the class and use this method?

Asked

Viewed 53 times

0

I really don’t see any difference in these two methods uses. Could someone be more specific with me and inform me about this?

  • 4

    Take a look at this post might help... http://answall.com/q/12651/11404

1 answer

3


A static method should be created if it makes sense to have it without an instance of the Object.

Simple example: in a class Geladeira you may have a static method double converterCelsiusFahrenheit(double celsiu) even if it does not have a refrigerator. Already the method void adicionarItem(Item item) is referencing a specific refrigerator, so it shouldn’t be static, since it needs an instance.

  • Got it!!!!!!! Now it makes sense.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.