1
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Overloading and polymorphism have nothing to do with each other. I assume you meant overriding. :) \$\endgroup\$ Commented Aug 15, 2012 at 7:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .