title: Why downcasting does not throw exception if returned from hashmap as value
body: <p>I have some class as</p>
  
  <pre><code>public class Container {
      static Map&lt;String , Fruits&gt; mp = new HashMap&lt;String, Fruits&gt;();
      public static Map&lt;String, Fruits&gt; getMp() {
          return mp;
      }
  }
  </code></pre>
  
  <p>FruitsClass</p>
  
  <pre><code>public class Fruits {
          private String color;
          private String shape;
          public String getColor() {
              return color;
          }
          public String getShape() {
              return shape;
          }
      }
  </code></pre>
  
  <p>Class Apple which extends Fruits</p>
  
  <pre><code>public class Apple extends Fruits {
      private String color;
      private String shape;
      public String getColor() {
          return color;
      }
      public void setColor(String color) {
          this.color = color;
      }
      public String getShape() {
          return shape;
      }
      public void setShape(String shape) {
          this.shape = shape;
      }   
  }
  </code></pre>
  
  <p>Main Class</p>
  
  <pre><code>public static void main(String[] args) {
      Apple a = new Apple();
      a.setColor("red");
      a.setShape("round");
  
      Container.getMp().put("fruits1",a);
      System.out.println(Container.getMp().get("fruits1").getShape());
      Apple b =(Apple) Container.getMp().get("fruits1");//does not throw runtime exception
  
      Fruits f = new Fruits();
      Apple as = (Apple) f;//throw runtime exception
  
  }
  </code></pre>
  
  <p>My question is that in both case I am downcasting Fruits to Apple But when the value comes from hashmap it does not throw exception.I am quite confused in this.Please someone can explain me the reason behind this. </p>