title: Why does classLoader load only the main class but not any other referenced class?
body: <p>Say I have the following:</p>
  
  <pre><code>public class Foo {
      static {
         System.out.println("Foo static initialization is working")
      }
  
      public void sayHello {
         System.out.println("Hello Foo")
      }
  }
  
  public class Bar {
      static {
         System.out.println("Bar static initialization is working")
      }
  
      public void sayHello {
         System.out.println("Hello Bar")
      }
  }
  
  public class HelloMain {
       public static void main() {
         Foo foo  = new Foo();
         foo.sayHello();
         Bar bar  = new Bar();
         bar.sayHello();
       } 
  }
  </code></pre>
  
  <p>Here is my custom classLoader:</p>
  
  <pre><code>public class MyClassLoader extends ClassLoader {
      public MyClassLoader() {
          super(MyClassLoader.class.getClassLoader());
      }
  
      public MyClassLoader(ClassLoader parent){
          super(parent);
      }
  
      public Class loadClass(String name) throws ClassNotFoundException {
          System.out.println(name + " ************"); // why Foo and Bar are not coming through here?
          return super.loadClass(name);
  
      }
  }
  </code></pre>
  
  <p>Say I package all this as jar and the name of my jar file be "hello.jar"
  and run the following command:</p>
  
  <pre><code>java -Djava.system.class.loader=MyClassLoader -jar hello.jar
  </code></pre>
  
  <p>It prints all the standard java class as well as HelloMain class from the code above however the Foo and Bar classes are not getting printed. I wonder why? Also, how can I change something so that the print statement in MyClassLoader prints Foo and Bar classes?</p>