Java - Are methods instantiated or initialized?

  • Context: Java 
  • Thread starter Thread starter Deathfish
  • Start date Start date
  • Tags Tags
    Java
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
Deathfish
Messages
80
Reaction score
0
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?

Thanks
 
Physics news on Phys.org
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>().
 
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: