title: Memory layout in Java
body: <p>I went through a Java test at my high school. One question bothered me too much as I was blank as how would I solve it.</p>
  
  <p>Consider the following Java code:</p>
  
  <pre><code>interface Pingable {
    public void ping();
  }
  
  class Counter implements Pingable {
    int count=0;
    public void ping(){++count;}
    public int val(){return count;}
  }
  
  public class Ping {
    public static void main(string args[])
    {
      Counter c=new Counter();
      c.ping();c.ping();
      int v=c.val();
      System.out.println(v);
    }          
  }
  </code></pre>
  
  <p>Assume that this is to be compiled to native code on a machine with 4 byte addresses. Draw a picture of the layout in memory for counter object. Show all virtual function tables.</p>