There are several classes (Character1, Character2 ...) that implement the Actor interface. Everyone has a jump () method. How to call jump () from Character2 using a parameter?

  • The question is not entirely clear. You need this: Actor char2 = new Character2(); char2.jump(); Actor char2 = new Character2(); char2.jump(); ? - Yuriy SPb
  • param - parameter (now equal to 2, for example) player - an instance of a buffer class that implements the call logic. It is necessary to: player (param) .jump (); was equal to Character2.jump (); This is just offhand. So far, I am only estimating the optimal implementation. - Cosmic Flow

1 answer 1

You will need type conversion (descending) and for convenience the class enum. Create an Actor person, and then, depending on the class you need, create the necessary one, ie:

 Actor person; if(ActorType.CHARACTER1 == param) { //enum ActorType actor = new Character(); } else if(...) { ... } 

something like this...