java Stack vs Heap

Heap  Stores :

class(static fields) and instance variables, method code  and Object instances.

Stack  Stores :

local method/local variables and method calls.

According to java 6 some of the instances may be stored in Stack also

public class Bicycle{ 
 // Class Variable
    private static int numberOfBicycles = 0;

// instance variable       
    private int id;
// Object instace 
   private  Bicycle  b=null;
 public int Method1() { 
     // local variables
      int i=1;
     return i;

No comments:

Post a Comment