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