Java Java - Are methods instantiated or initialized?

  • Thread starter Thread starter Deathfish
  • Start date Start date
  • Tags Tags
    Java
AI Thread Summary
Instantiation refers to the creation of objects from a class, while initialization involves assigning values to variables. In the context of methods, they are not instantiated or initialized in the same way as variables or objects. Instead, methods are defined within a class and are executed when called using the syntax <object name>.<method name>. Static methods and instance methods are part of the class definition and are linked to the application when the class is compiled, not when individual objects are created. This distinction is crucial for understanding object-oriented programming, especially for beginners, as delving into more complex details may lead to confusion.
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
 
Technology 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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top