开发者

Multiple superclasses in Objective-C?

Can I inherit from multiple classes in Objective-C? (If ye开发者_运维百科s, how so?)


As others have said, Objective-C is single-inheritance. However, protocols provide handy ways to get around any type of situation you might have wanted multiple inheritance for and they allow you to avoid pitfalls that multiple inheritance creates such as The Diamond Problem.

Edit: Changes interface to protocol. Sorry, getting Java and Obj-C mixed up.


No, Objective-C is single-inheritance only.

Consider looking at protocols which are a way of exposing a declared interface from a class. It's not the same as multiple inheritance, but solves some needs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜