Concept Flow - Instance methods
Create Object
Call Instance Method
Method Uses Object's Data
Method Executes and Returns
Back to Caller
An instance method is called on an object, uses that object's data, runs its code, then returns control back.
class Dog { String name; void bark() { System.out.println(name + " says Woof!"); } } public class Main { public static void main(String[] args) { Dog d = new Dog(); d.name = "Buddy"; d.bark(); } }
| Step | Action | Object State (name) | Output |
|---|---|---|---|
| 1 | Create Dog object d | null | |
| 2 | Set d.name = "Buddy" | Buddy | |
| 3 | Call d.bark() | Buddy | Buddy says Woof! |
| 4 | Method bark() finishes | Buddy |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|---|
| d.name | null | null | Buddy | Buddy | Buddy |
Instance methods belong to objects. They use the object's data (fields). Called with object.methodName(). Can access and modify object state. Return control after execution.