Java - Are methods instantiated or initialized?

  • Java
  • Thread starter Deathfish
  • Start date
  • #1
86
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
 

Answers and Replies

  • #2
CompuChip
Science Advisor
Homework Helper
4,302
47
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>().
 
  • #3
AlephZero
Science Advisor
Homework Helper
6,994
291
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:

Related Threads on Java - Are methods instantiated or initialized?

Replies
3
Views
3K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
3
Views
6K
Replies
4
Views
127
Replies
1
Views
2K
Replies
3
Views
2K
Replies
9
Views
4K
Replies
4
Views
2K
Top