You can't do it in first palce . Other thing is to deal with such kind of problems like you recieve an object and you have to cast it to one amonst many of your own classes (adn you don't know which type comes when) , have an interface with all common functions defined in it and always cast your object to that Interface and call the method . By run-time polymorphism , always proper method will get called.