title: How to convert string type to my own user class type in java
body: <p>I have two classes like FirstClass and SecondClass. In the FirstClass I declared a variable with String type and then I assigned that variable to the SecondClass type. But it shows an exception. Please help.</p>
  
  <p>Here is the code.</p>
  
  <p>FirstClass.java</p>
  
  <pre><code>public static void main(String[] args) {
      // TODO Auto-generated method stub
      SecondClass sc;
      String a = "world";
      Object obj = a;
      sc = (SecondClass) obj;
      System.out.println("" + sc);   
  }
  </code></pre>
  
  <p>ErrorMessage.</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to com.study.SecondClass
  at com.study.FirstClass.main(FirstClass.java:13)
  </code></pre>