Can I inherit from multiple classes in Objective-C? (If yes, how so?)
In keeping with its clean and simple design, Objective C does not support multiple inheritance, though features have been developed to replace some of the functionality provided by multiple inheritance (see run-time section below). The root of the Objective C class hierarchy is the Object class.
Object-Oriented ProgrammingMultiple inheritance means that a subclass can inherit from two or more superclasses. C++ allows multiple inheritance, but Java allows only single inheritance, that is, a subclass can inherit only one superclass.
In Java, a subclass can only extend one superclass.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With