title: How to call a method from class created using classloader
body: <pre><code>import java.lang.*;
  public class firstclass
  {
  public static void main(String[] args)
  { ClassLoader classLoader = firstclass.class.getClassLoader();
  
      System.out.println("class A is called ...");
           try {
          Class x=classLoader.loadClass("secondclass");
           System.out.println("x has been initialized"+x);
           //Object y=x.newInstance();
           //y.disp();
        } catch (Exception e) {
           e.printStackTrace();
  
        } 
  
  }
  }
  </code></pre>
  
  <p>Second program is</p>
  
  <pre><code>public class secondclass
  {
  public void disp()
  {
  System.out.println("Clss B is Called")
  }
  }
  </code></pre>
  
  <p>when i execute this program i get output as </p>
  
  <pre><code>Class A called
  x has been initializedsecondclass
  </code></pre>
  
  <p>but if try to call <code>x.disp()</code>or</p>
  
  <pre><code>Object y=x.newInstance();
  y.disp();
  </code></pre>
  
  <p>then i get the error as object not found. how to get the object of x to call disp()</p>