title: Create a base class object from a derived class
body: <p>I have the following classes:</p>
  
  <pre><code>public class Base{
  
      //fields
      public String getStr(){
          String str = null;
          //Getting str from the fields
          return str;
      }
  }
  
  public class Derived extends Base{
  
      //fields
      //some other fileds
      public String getStr(){
          String str = null;
          //Getting str from the fields + some other fields
          return str;
      }
  }
  </code></pre>
  
  <p>Now, I have a method which has a parameter of the type <code>Derived</code>.</p>
  
  <pre><code>public void makeStr(Derived d){
      Base b = null;
      //Getting the Base class subobject from d and printing the str
  }
  </code></pre>
  
  <p>But I can't just do assignment like <code>b = d;</code> and then invoke <code>b.getStr()</code> because the method <code>d.getStr()</code> is going to be called. </p>
  
  <p>How can I create the object of the type <code>Base</code> from the <code>Base</code> subobject of the objec of the type <code>Derived</code>? I fact, I just wanta create the copy of the <code>Base</code> subobject of the type <code>Derived</code>.</p>