In PHP, how many parents may a single class have, and what is this process called? [closed]
Thanks for your replies. Appreciate it a lot!
PHP supports single inheritance, where a child class (or subclass) may directly inherit from at most one parent class (or superclass). That parent class may in turn inhert from it's own parent, to an arbitrary number of levels (there may be some technical limit, but you will never hit it in practice).
This is in contrast with multiple inheritance languages which allow a given class to inherit from several parents.
how many parents may a single class have
One
what is this process called?
Inheritance
Hmmm...
how many parents may a single class have
From another point of view, if you have :
class Animal {
public function doA() {}
}
class Human extends Animal {
public function doB() {}
}
class Jedi extends Human {
public function doC() {}
}
A Jedi is a Human, but he is also an Animal. This is polymorphism.
As you can see, a class may have any number of parents.
The answer to your question is clearly one, but it should have been written :
how many classes may a single class extend
精彩评论