Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Method (computer programming)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Static methods=== {{see also|Static member function}} Static methods are meant to be relevant to all the instances of a class rather than to any specific instance. They are similar to [[static variable]]s in that sense. An example would be a static method to sum the values of all the variables of every instance of a class. For example, if there were a <code>Product</code> class it might have a static method to compute the average price of all products. A static method can be invoked even if no instances of the class exist yet. Static methods are called "static" because they are resolved at [[compile time]] based on the class they are called on and not dynamically as in the case with instance methods, which are resolved polymorphically based on the runtime type of the object. ====Examples==== =====In Java===== In Java, a commonly used static method is: Math.max(double a, double b) This static method has no owning object and does not run on an instance. It receives all information from its arguments.<ref name=":0">{{Cite book|title = Clean Code: A Handbook of Agile Software Craftsmanship|last = Martin|first = Robert C.|publisher = Prentice Hall|year = 2009|isbn = 978-0-13-235088-4|pages = 296|author-link = Robert Cecil Martin}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)