title: newInstance() | ClassNotFoundException | NoClassDefFounfError
body: <p>following is the code, when i am giving command java Test A then i am getting error NoClassDefFoundError and when i give command java Test S then error is ClassNotFound.</p>
  
  <p>As per my knowledge if newInstance() is used and class is not found then ClassNotFound error should com</p>
  
  <p>Why is there difference in the errors? </p>
  
  <p><a href="https://i.stack.imgur.com/uG8oa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uG8oa.png" alt="enter image description here"></a></p>
  
  <pre><code>class Test {
  
  public static void main(String[] args) throws Exception
  {
      System.out.println("In Main Method");
      Object o = Class.forName(args[0]).newInstance();
      System.out.println(o.getClass().getName());
  }
  
  }
  
  class Student
  {
  
  }
  
  class Teacher
  {
  
  }
  </code></pre>