Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java Java - Are methods instantiated or initialized?

  1. Nov 26, 2013 #1
    I tried searching difference between instantiation and initialization but all results were about either variables or objects.

    But what about methods? Are methods instantiated or initialized?

    static methods?
    instance methods?

  2. jcsd
  3. Nov 26, 2013 #2


    User Avatar
    Science Advisor
    Homework Helper

    Objects are instantiated.
    Variables are initialized (or not).
    Methods are called. They don't "exist" in the same sense variables and objects do - they are part of the definition of a class and are executed when you write <object name>.<method name>().
  4. Nov 26, 2013 #3


    User Avatar
    Science Advisor
    Homework Helper

    If you want, you can think of "methods" as being "final static" members of a class, so they are "instantiated" and "initialized" once for the class (not when you create objects whose type is the class), when the Java system links the complied class definition into your application, before any code that you wrote starts to execute.

    Actually things can get more complicated than that, but if you are doing a first course on Java and/or OO programming, the full story would probably cause more confusion not less.
    Last edited: Nov 26, 2013
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook