All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.pdx.cs410J.lang.WhatAmI Maven / Gradle / Ivy

The newest version!
package edu.pdx.cs410J.lang;

/**
 * This program uses Java's reflection mechanism to print the name of
 * a given Object's class.
 */
public class WhatAmI {

  /**
   * Prints out the name of a given Object's class.
   */
  private static void whatAmI(Object o) {
    Class c = o.getClass();
    System.out.println("I (" + o + ") am a " + c.getName());
  }

  public static void main(String args[]) {
    whatAmI("Hello");
    whatAmI(new Integer(4));
    whatAmI(new Double(2.7));
    whatAmI(new Cow("Tootie"));
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy