title: How to cast parent into child in Java
body: <p><strong>I am doing this:<br></strong></p>
  
  <pre><code>Child child = (Child)parent;
  </code></pre>
  
  <p>Which gives me an error, I found it isn't possible to do it like this. I don't know exactly why, but I think it should be possible, if <code>Child</code> class inherits from <code>Parent</code> class, it contains the <code>Parent</code> object data.</p>
  
  <p><strong>My questions are:</strong> </p>
  
  <ul>
  <li>Why it doesnt work?</li>
  </ul>
  
  <p><br></p>
  
  <ul>
  <li>How can i make this work, without setting every single parent's
  attribute like this</li>
  </ul>
  
  <p>:</p>
  
  <pre><code>class Parent{
      public int parameter1;//...
      public int parameter1000;
  }
  
  class Child extends Parent
  {
      public Child(Parent parent)
  {
          this.parameter1 = parent.parameter1;//...
          this.parameter1000 = parent.parameter1000;
  }
  }
  </code></pre>