title: How to get the name of the calling class in Java?
body: <p>I would like some help on this matter, </p>
  
  <p>Example:</p>
  
  <pre><code>public class A {
      private void foo() {
          //Who invoked me?
      }
  }
  
  public class B extends A {}
  
  public class C extends A {}
  
  public class D {
       C.foo();
  }
  </code></pre>
  
  <p>This is basically the scenario. My question is how can method <code>foo()</code> know who is calling it?</p>
  
  <p><strong>EDIT</strong>: Basically I am trying to do a database Layer, and in <code>class A</code> I will create a method that will generate SQL statements. Such statements are dynamically generated by getting the values of all the <code>public</code> properties of the calling <code>class</code>.</p>