Stack and Heap are the memory location in the JVM where variable and object can be stored.
Instance variable------------
|-----------> can be stored in the heap memory
Objects---------------------
Local variable ----------------------> can be stored in the stack memory
for example :
class A{
int a; ------------------>Instance variable
string b;
|--------------------->local variable
void getName(String name)
{
this.name;
}
public static void main(String arg[])
{
A a = new A();----------------------object
A.getName("siva");
}
}
Here in this program,
A a;----------->This can be stored in stack memory.
new A();------->This can be stored in heap memory.
Instance variable------------
|-----------> can be stored in the heap memory
Objects---------------------
Local variable ----------------------> can be stored in the stack memory
for example :
class A{
int a; ------------------>Instance variable
string b;
|--------------------->local variable
void getName(String name)
{
this.name;
}
public static void main(String arg[])
{
A a = new A();----------------------object
A.getName("siva");
}
}
Here in this program,
A a;----------->This can be stored in stack memory.
new A();------->This can be stored in heap memory.
its good.........!
ReplyDelete