+ 3

Why we need Static methods in java?

i know that we can call a static method with class name. but what is the benefit of using it?

16th Jan 2018, 5:39 AM
sal sal
sal sal - avatar
1 Odpowiedź
+ 6
static methods in the following scenarios only: 1) If you are writing utility classes and they are not supposed to be changed. 2) If the method is not using any instance variable. 3)If any operation is not dependent on instance creation. 4) If there is some code that can easily be shared by all the instance methods, extract that code into a static method. 5) If you are sure that the definition of the method will never be changed or overridden. As static methods can not be overridden. that's why we use static methods in java
16th Jan 2018, 5:45 AM
GAWEN STEASY
GAWEN STEASY - avatar