Answer: This code illustrates what is happening behind the scenes in the JVM to support services from multiple classes. This example is patterned after the use of typical awt widget services. The class "AServicer" provides one simple service (think of it as replacing an "Applet" type service class), the class "SomeServiceProvider" provides another (think of it as replacing a "TextField" type service class). The counterparts to class "SomeServiceProvider" therefore are "buried" inside the virtual machine. This example reveals how they work. The class "SomeEvent" is analogous to "ActionEvent" or some similar Java class. This example shows how the event classes work with the service provider classes. See the "IMPORTANT" note below to understand how "implements" helps fake multiple inheritance. Code in green indicates JVM counterparts. Code in blue indicates user code.

// Example of how JVM uses "interface" to provide services from multiple
// classes, as though there is multiple inheritance.

// Service provided by class "AServicer": return unique even or odd numbers,
// beginning with the value of "number" passed through the constructor,
// every time "service()" is invoked.
class AServicer {
   int number;
   AServicer (int number) { this.number = number-2; }

   public int service() {  return number+=2; }

// This is the interface through which the service provider below is able
// to provide its service.
interface SomeServiceListener { void performService (SomeEvent evt); }

// Event associated with providing the service below
class SomeEvent {
   SomeServiceProvider service;
   SomeEvent (SomeServiceProvider service) { this.service = service; }
   public SomeServiceProvider getSource() { return service; }

// Service provided by class "SomeServiceProvider": return a unique number 
// every "timer" seconds.  
// IMPORTANT: here is how the "interface" works:
//   "listener" can be ANY class implementing SomeServiceListener
//   since "listener" must implement "performService"
//   it can be invoked below, for sure, to get some result.
//   If "listener" is not implementing "SomeServiceListener" the method
//   "addSomeListener" below will fail and no listening will be provided!!!
//   Thus, ONLY classes implementing "performService" are accepted for
//   servicing.
class SomeServiceProvider extends Thread {
   int number, timer; SomeServiceListener listener;

   public SomeServiceProvider (int timer) { number = 0; this.timer = timer; }

   public void addSomeListener(SomeServiceListener listener) { 
      this.listener = listener; 

   public void run () {
      while (true) { 
         try { sleep(1000*timer); } catch (Exception e) {} 
         if (listener != null) listener.performService(new SomeEvent(this));

// Inherit services from more than one class via "extend" and "implements".
// Service performed by class "AServicer": return unique even numbers 
// starting with "10" in this case, every time "service()" is invoked.  
// Service performed by class "SomeServiceProvider": return successive
// numbers starting with "1" every 3 and 5 seconds (two objects).
// Both services are utilized when "performService" is invoked due to 
// interruptions generated by two "SomeServiceProvider" Threads.
class A extends AServicer implements SomeServiceListener {
   SomeServiceProvider service1, service2;

   A (int a) { 
      service1 = new SomeServiceProvider(3);  // interrupt every 3 seconds
      service2 = new SomeServiceProvider(5);  // interrupt every 5 seconds

   public void performService (SomeEvent evt) {
      if (evt.getSource() == service1) {
         System.out.print("Service 1:["+service1.number+":"+service()+"] ");
      } else if (evt.getSource() == service2) {
         System.out.print("Service 2:["+service2.number+":"+service()+"] ");

public class FakeMultipleInheritanceExample {
   public static void main (String arg[]) {
      A a = new A(10);

The following is a comparable applet using textfields as service providers

//import java.applet.*;
//import javax.swing.*;
//import java.awt.event.*;

//public class MultipleInheritance extends Applet implements ActionListener {
//   JTextField service1, service2;

//   public void init () { 
//      add(service1 = new JTextField(20)); 
//      add(service2 = new JTextField(20));
//      service1.addActionListener(this);
//      service2.addActionListener(this);
//   }

//   public void actionPerformed (ActionEvent evt) {
//      if (evt.getSource() == service1) {
//         System.out.print("Service 1:["+service1.getText()+"] ");
//      } else if (evt.getSource() == service2) {
//         System.out.print("Service 2:["+service2.getText()+"] ");
//      }
//   }