开发者

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

开发者 https://www.devze.com 2023-01-05 00:22 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
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

精彩评论

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