class Student{ int num; // num is instance variable public void showData{} Local variables are declared inside a method including method arguments. public void sum(int a){ int x = int a + 3; // a , x are local variables }
Points to Remember:
- When a method is called , a frame is created on the top of stack.
- Once a method has completed execution , flow of control returns to the calling method and its corresponding stack frame is flushed.
- Local variables are created in the stack Instance variables are created in the heap & are part of the object they belong to.
- Reference variables are created in the stack.
Posted in: