import java.lang.reflect.Method;

class Animal {
  private int weight;

  public Animal() {
    weight = 100;
  }

  public Animal(int w) {
    weight = w;
  }

  public double price() {
    return weight * 18.0;
  }

  public String toString() {
    return "Animal";
  }
}

public class Reflection {
  public static void main(String[] args) {
    try {
      Class cls = Class.forName("Animal");
      // Get only the declared methods:
      Method methods[] = cls.getDeclaredMethods();
      for (Method m : methods) {
        System.out.println(m);
      }
      // Create a new instance of the class:
      Animal a = (Animal) cls.newInstance();
      // Invoke price over the new instance:
      Method m = cls.getMethod("toString", null);
      System.out.println("Invoking a method on " + m.invoke(a, null));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
