开发者

In PHP, how many parents may a single class have, and what is this process called? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the h开发者_如何学Goelp center. Closed 10 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜