title: When to cast a variable
body: <p>Casting in Apex seems like Black Magic to me. I don't get when should we make an explicit cast, and when it can be implicit. Like:</p>
  <p>Recipe.apxc</p>
  <pre><code>public virtual class Recipe{
      public string nome;
      protected string instructions;
      private String source = 'Granny';
      
      public Recipe() {}
  
      public Recipe(String inpNome, String inpInstrucoes) {
          nome = inpNome;
          instructions = inpInstrucoes;
      }
      
      public void printDescription(){        
          system.debug('Name: ' + nome + ', Instructions: ' + instructions);
          return;
      }
  }
  </code></pre>
  <p>DrinkRecipe.apxc</p>
  <pre><code>public class DrinkRecipe extends Recipe{
      public String nome = 'Luso';
      
      private String glassType;
      
      public DrinkRecipe(String inpNome, String inpInstrucoes){
          
          super(inpNome, inpInstrucoes);
      }
  }
  </code></pre>
  <p>in the annonymous window</p>
  <pre><code>DrinkRecipe dr = new DrinkRecipe('Whater', 'glu, glu', 'normal');
  
  // why does this work? Shouldn't i always need to cast an object to make it use another constructor, from another class?  
  Recipe r1 = dr;
  system.debug(r1.nome);
  
  // I thought explicit casting like this would be the only way  
  Recipe r2 = (Recipe) dr;
  system.debug(r2.nome);
  </code></pre>
  <p>Thanks</p>