Another question on inheritance

From a quick Google search and Wikipedia article on multiple inheritance, which quotes:

Multiple inheritance refers to the characteristic of some object-oriented programming languages ​​in which a class can inherit behavior and functions from more than one superclass. This contrasts with single inheritance when a class can inherit no more than one superclass.

I understand that PHP does not allow multiple inheritance. However, I cannot find a clear answer to the question of whether this allows more than one class to extend the superclass. Example:

class a {}
class b extends a {}
class c extends a {}

In terms of what I'm trying to do, I am doing an RPG and want the "generic" character class to include all the methods and properties that create the character template. Then I want the classes to include specifics for each type of character (warrior, mage, etc.), such as statistics modifiers and special attacks.

Is it possible?

+3
source share
5 answers

Yes, it is quite possible. The whole purpose of inheritance is that multiple child objects can inherit common functionality from the parent.

+2
source

Yes, multiple classes can extend the same class according to your code example.

+2
source

. .

+1

, . , c a, b.

+1

So in a adjusted example like the one above

class a {}
class b extends a {}
class c extends b {}

c could not get properties a?

0
source

Source: https://habr.com/ru/post/1761220/


All Articles