Like so : a class has a method called sayHello() . When a instance of the class call the sayHello(), a method in another class is called automatic before the sayHello() is
Check AspectJ, and aspect-oriented programming framework. It will allow you to do something similar.
You see, in order to make this happen, you class should be managed by some container which instantiates your objects and makes proxies of them.
AspectJ has an alternative by plugging some "magic" into the VM.