import java.lang.reflect.*;

public class Teste {

   // Declara campos (fields) globais.
   String nome; 
   String sobrenome;
   String temp;
   private String negado;
   String nula;
   
   // Construtor
   public Teste(String n, String s) {
      this.nome = n;
      this.sobrenome = s;
      this.temp = "temporario";
   }

   // Construtor 2
   public Teste() {}

   // Construtor protected pede int
   protected Teste(int x) {}

   // Construtor private pede String
   private Teste(String x) {}

   public void temp() {
      temp = "temporario";
      String TEMP = "TEMPORARIO";
   }

   protected void metodo1() {}

   private void metodo2() {}

   private int metodo3() {return 2;}

   public static void main(String args[]) {
      Teste o = new Teste("Bruno", "Borges");
      try {
        if (o == null) return;
        Class cl = o.getClass(); // pega a classe do objeto.
        Field fields[] = cl.getDeclaredFields(); // pega os campos da classe
        Method metodos[] = cl.getDeclaredMethods(); // pega os metodos da classe
        Constructor all_const[] = cl.getDeclaredConstructors(); // pega todos os construtores
        Constructor pub_const[] = cl.getConstructors(); // pega os construtores public

        // Lista os campos 
        System.out.println("Campos da classe"); 
        for (int i=0; i<fields.length; i++) {
              Field field = fields[i];
              Class fieldType = field.getType();
              System.out.println(fieldType.getName() + " " + field.getName());
              try {
                   field.setAccessible(true); // permite acessar campos private
                   Object member = field.get(o);
                   System.out.println("\ttem valor: " + member);
              } catch(IllegalAccessException e) {
                 System.out.println("\t" + e);
              }
        }
        System.out.println("");

        // Lista os metodos da classe
        System.out.println("Metodos");
        for(int i=0;i<metodos.length;i++) {
           System.out.println(metodos[i]);
        }
         System.out.println("");
         
        // Lista os Construtores publicos da classe
        System.out.println("Construtores");
         for(int i=0;i<pub_const.length;i++) {
            System.out.println(pub_const[i]);
         }
          System.out.println("");

       // Lista todos os construtores da classe
          System.out.println("Todos os Construtores");
          for(int i=0;i<all_const.length;i++) {
             System.out.println(all_const[i]);
          }
          System.exit(1);
      } catch(Exception e) {
         System.out.println(e);
      }
   }
}
