I'm making a collision handler for a Java game engine. I made an interface called Collidable. I have a method called onCollision which takes the parameter of my Engine Game Object.

public void onCollision(engine.objects.Object obj) {


I want to know how I can redo this so that I can give individual instructions for each Collidable object's onCollision method for how to collide with a Wall object or an Enemy object without having to write another method that has the parameters Wall and Enemy so that my engine is flexible.

How can I do this?


You are about to begin your journey into Overloading, it's an essential part of the Polymorphism.

The first result from Google is just enough to give you an idea.

This topics are the basic topics for every Java programmer and in general for every programmer who wants to code in an OO way, i suggest to pick a good book that can teach you the basic stuff or a good online resource.

  • 1
    \$\begingroup\$ Overloading and polymorphism have nothing to do with each other. I assume you meant overriding. :) \$\endgroup\$ – Sean Middleditch Aug 15 '12 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.