How to solve java multi inheritance?

Viewed 53

Lets say i have a base class Entity with variables for position.

public class Entity {
    private int position;
}

Now i want a classes that have variables for speed, health, damage and any combination of those. like:

public class MovingAndHealth extends Entity {
    private int speed;
    private int health;
}

Is there a way to do this or do i have to make all variations manually?

2 Answers

Second option is not to inherit, but create a class which has inside the instances of all your "child classes"

You can only extend one class, but multiple inheritance in Java is achieved with interfaces.

Related