0

In many languages, e.g. Java and JavaScript, the 'static' keyword refers to class methods or class variables.

  • Why is it called the 'static' method? Why not 'blue' method? Or 'global' method?
  • Where does the keyword come from? What is the origin for that denomination?
  • Is it related to the compiler?
tquadrat
  • 3,033
  • 1
  • 16
  • 29
Ryan Lyu
  • 4,180
  • 5
  • 35
  • 51
  • 3
    Probably static because it doesn’t change like one bound to an instance – evolutionxbox Mar 21 '20 at 13:55
  • This looks like an "opinion" type question, and anyway does not ask a specific programming question as it relates to solving programming issues as outlined by SO guidelines. It may be a good question for another site in the vast StackExchange network, however. Also SO requests single well defined questions, rather than multiple open-ended questions in a single post. See the [Help Center](https://StackOverflow.com/help) and [what not to ask](https://stackoverflow.com/help/dont-ask) for more info. – SherylHohman Mar 21 '20 at 23:18

1 Answers1

1

To answer to ur 1st and 2nd question
A static method belongs to the class itself so a static method is also called class method.
For example The main() method must be static so the Java Virtual Machine can invoke its without create an instance of the class, to run a Java program.
Since static method does not depend on class object i.e. instance talking about inheritance in Java the method is always called by the reference irrespective of the instance Object it is pointing at.

To answer to ur third question
When the compiler compiles that class it decides at compile time which exact method is called for each static method call (that's the big difference to non-static method calls: the exact method to be called is only decided at run time in those cases). just to add to static method in Java
The static final values in compiled version saved directly in the class itself, if they are compile-time initialized primitives.

Amit Kumar Lal
  • 5,537
  • 3
  • 19
  • 37