What’s the difference between a public static method and a public method? Why would you use a public static method?
What’s the difference between a public static method and a public method? Why would
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The methods of the Math class are static. So, in doing
the Math class itself is unchanged by what you’ve done – it only returns a value or acts upon the value you pass.
So – static methods are useful for utilities. Things like
or
It’s very unusual that you’d use a static method for anything else. Don’t use statics like ‘getInstance()’ to create Singletons – look into a framework for dependency injection instead.