// Recipe.java -- demonstrate effects of overriding methods
// and shadowing variables, with and without casting.
public class Recipe
   {
   public static void main (String [] args)
      {

      // check behaviour of static functions and variables.

      out.println( Grandma.name() );
      // Bessie

      out.println( Mom.name() );
      // Rhonda

      out.println( Grandma.age );
      // 70
      out.println( Mom.age );
      // 30

      Grandma grandma = new Grandma();
      Mom mom = new Mom();
      Grandma confuser = new Mom();

      // check behaviour of static functions and variables
      // called in a permitted, but not very wise, manner

      out.println( grandma.name() );
      // Bessie

      out.println( mom.name() );
      // Rhonda

      out.println( confuser.name() );
      // Bessie !

      out.println( grandma.age );
      // 70

      out.println( mom.age );
      // 30

      out.println( confuser.age );
      // 70 !

      // check out instance behaviour of instance functions and variables.

      out.println( grandma.recipe() );
      // light a fire

      out.println( mom.recipe() );
      // open a can

      out.println( confuser.recipe() );
      // open a can

      out.println( grandma.cups );
      // 20

      out.println( mom.cups );
      // 1

      out.println( confuser.cups );
      // 20 !

      // check out instance behaviour of casted
      // instance functions and variables.

      out.println( ((Grandma)mom).recipe() );
      // open a can !!!

      out.println( ((Grandma)mom).cups );
      // 20 !!

      out.println( ((Mom)confuser).recipe() );
      // open a can !

      out.println( ((Mom)confuser).cups );
      // 1 !

      // check out instance behaviour of
      // variables accessed internally

      out.println( grandma.getCups() );
      // 20

      out.println(mom.getCups() );
      // 20 !!!

      out.println( confuser.getCups() );
      // 20 !

      out.println( ((Grandma)mom).getCups() );
      // 20 !

      out.println( ((Mom)confuser).getCups() );
      // 20 !

      }  // end main

   } // end class Recipe

class Grandma
   {

   public static String name()
      {
      return( "Bessie" );
      }

   public static int age = 70;

   String recipe()
      {
      return( "light a fire,..." );
      }

   public int cups = 20;

   public int getCups()
      {
      return cups;
      }

   } // end class Grandma

class Mom extends Grandma
   {

   public static String name()
      {
      return( "Rhonda" );
      }

   public static int age = 30;

   public String recipe()
      {
      return( "Open a can ..." );
      }

   public int cups = 1;

   } // end class Mom