Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define a multi interface Variable

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();
like image 494
Alberto Zanovello Avatar asked Apr 15 '26 10:04

Alberto Zanovello


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();
like image 195
Alberto Zanovello Avatar answered Apr 16 '26 22:04

Alberto Zanovello



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!