In Java, methods are neither instantiated nor initialized in the same way as variables or objects. Instead, methods are part of a class definition and are executed when called, using the syntax
PREREQUISITES
Understanding of Java class structure
Knowledge of static and instance methods in Java
Familiarity with object-oriented programming concepts
Basic understanding of Java compilation process
NEXT STEPS
Research Java class definitions and their components
Learn about the Java compilation process and linking
Explore the differences between static and instance methods in Java
Study object-oriented programming principles in depth
USEFUL FOR
Java developers, computer science students, and anyone interested in understanding the nuances of method behavior in object-oriented programming.
#1
Deathfish
80
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?
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.