title: How does Java (or C++) handles invocation of methods defined in interfaces
body: <p>I am currently working on my programming language and it will have only interfaces and no object inheritance. And I have an issue, because I don't know how to make a vtable so an appropriate method could be called in a class with many interfaces inherited.</p>
  
  <p>In Java, you can write like this</p>
  
  <pre><code>interface A {
      void a();
  }
  
  interface B {
      void b();
  }
  
  interface C {
      void c();
  }
  
  class Something1 implements A, B{
      ... implementing a() and b() ...
  }
  
  class Something2 implements B, C{
      ... implementing b() and c() ...
  }
  
  ...
  
  B obj = new Something1();
  obj.b();
  
  obj = new Something2();
  obj.b();
  </code></pre>
  
  <p>And the JVM will call b() method with the only knowledge that the object inherits B interface <em>(if not optimized)</em></p>
  
  <p>So I think, firstly JVM will go to the vtable of the object and then ... How can it find b() in the vtable and what kind of vtable must be generated.</p>
  
  <p>P.S The question is not about Java at all. It could be an example with C++ or PHP, it doesn't matter. It's just simplier to write an example in Java</p>