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

0

I really do not see a difference in these two uses of methods. Could someone be more specific with me and let me know about this?

    
asked by anonymous 30.11.2016 / 14:00

1 answer

3

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

Simple example: In a Geladeira class you can have a static double converterCelsiusFahrenheit(double celsiu) method even if you do not have a refrigerator. Since the void adicionarItem(Item item) method is referencing a specific refrigerator, so it should not be static, since it needs an instance.

    
30.11.2016 / 14:08