Question Regarding Polymorphism

What is the best way of finding out the runtime class of an object?

More specifically lets say there is a method that takes an Abstract Class as a parameter but the method should behave differently depending on which subclass of the abstract class is actually passed to it at runtime. How could the method know which subclass has actually been passed. Do you use the getClass() method, and if so how should the Class object be used? Or is there a better way?

Thanks for your help, Adam.

[505 byte] By [Naz027a] at [2007-11-27 7:03:05]
# 1
If it needs to behave differently, you should pass the functionality to the subclass. If you need to do runtime class checking to decide functionality, it means your design is bad.
-Kayaman-a at 2007-7-12 18:54:14 > top of Java-index,Java Essentials,Java Programming...
# 2

>More specifically lets say there is a method that takes an Abstract Class as a

> parameter but the method should behave differently depending on which

> subclass of the abstract class is actually passed to it at runtime.

That breaks the whole point of polymorphism.

EvilBroa at 2007-7-12 18:54:14 > top of Java-index,Java Essentials,Java Programming...
# 3
Thanks for your help I thought I was being stupid, you've answered my question as I've realized I was thinking about the problem in the wrong way. Cheers.
Naz027a at 2007-7-12 18:54:14 > top of Java-index,Java Essentials,Java Programming...