Java - Are methods instantiated or initialized?

  • Context: Java 
  • Thread starter Thread starter Deathfish
  • Start date Start date
  • Tags Tags
    Java
Click For Summary
SUMMARY

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 .(). Static methods and instance methods are defined within the class, and they are effectively "final static" members that are linked when the Java system compiles the class definition. This linking occurs before any user-written code executes, establishing that methods exist as part of the class structure rather than as standalone entities.

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.

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:

Similar threads

  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Top