Define a multi interface Variable

Viewed 81

I want to define a variable that implement 2 interface. Imove and Ijump are 2 interface.

class b implements Imove,Ijump {...}
class a implements Imove,Ijump {...}
Imove,Ijump player = new a();
Imove,Ijump player = new b();
player.Jump();
player.Move();
1 Answers

interface can inherit from (multiple) other interface with extends.

Define third interface.

interface MoveAndJump extends IMove,IJump{};

Use that third interface.

MoveAndJump player = new a();
player.jump();
player.move();
Related