Inheritance/Multiple: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (added a ";task:" and whitespace.)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(4 intermediate revisions by 4 users not shown)
Line 16:
=={{header|Ada}}==
Ada 2005 has added interfaces, allowing a limited form of multiple inheritance.
<langsyntaxhighlight lang="ada">package Multiple_Interfaces is
type Camera is tagged null record;
type Mobile_Phone is limited Interface;
type Camera_Phone is new Camera and Mobile_Phone with null record;
end Multiple_Interfaces;</langsyntaxhighlight>
{{omit from|Modula-2}}
 
=={{header|Aikido}}==
Aikido does not support multiple inheritance, but does allow multiple implementation of interfaces.
<langsyntaxhighlight lang="aikido">interface Camera {
}
 
Line 32:
 
class Camera_Phone implements Camera, Mobile_Phone {
}</langsyntaxhighlight>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$+"CLASSLIB"
DIM Camera{TakePicture}
Line 47:
PROC_inherit(CameraPhone{}, Camera{})
PROC_inherit(CameraPhone{}, MobilePhone{})
PROC_class(CameraPhone{})</langsyntaxhighlight>
 
=={{header|C}}==
C simulates Multiple Inheritance via Structures.
<syntaxhighlight lang="c">
<lang C>
typedef struct{
double focalLength;
Line 68:
Phone phoneSample;
}CameraPhone;
</syntaxhighlight>
</lang>
 
=={{header|C sharp|C#}}==
Line 77:
In the example we inherit from a class and an interface.
 
<langsyntaxhighlight lang="csharp">interface ICamera {
// ...
}
Line 87:
class CameraPhone: ICamera, MobilePhone {
// ...
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">class Camera
{
// ...
Line 105:
{
// ...
};</langsyntaxhighlight>
 
=={{header|Clojure}}==
<langsyntaxhighlight Clojurelang="clojure">(defprotocol Camera)
 
(defprotocol MobilePhone)
Line 114:
(deftype CameraPhone []
Camera
MobilePhone)</langsyntaxhighlight>
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> CLASS-ID.IDENTIFICATION CameraDIVISION.
CLASS-ID. Camera.
*> ...
END CLASS Camera.
IDENTIFICATION DIVISION.
CLASS-ID. Mobile-Phone.
*> ...
END CLASS Mobile-Phone.
IDENTIFICATION DIVISION.
CLASS-ID. Camera-Phone INHERITS Camera, Mobile-Phone.
CLASS-ID. Camera-Phone
CLASS-ID. Camera-Phone INHERITS FROM Camera, Mobile-Phone.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
Line 133 ⟶ 137:
*> ...
END CLASS Camera-Phone.</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
 
<langsyntaxhighlight lang="lisp">(defclass camera () ())
(defclass mobile-phone () ())
(defclass camera-phone (camera mobile-phone) ())</langsyntaxhighlight>
 
=={{header|D}}==
Line 145 ⟶ 149:
While D does not have multiple base class inheritance, you can inherit from multiple interfaces.
 
<langsyntaxhighlight lang="d">interface Camera {
// member function prototypes and static methods
}
Line 156 ⟶ 160:
// member function implementations for Camera,
// MobilePhone, and CameraPhone
}</langsyntaxhighlight>
 
D also supports the [[non-virtual interface]] pattern, where an interface may have non-virtual methods with defined implementations.
 
<langsyntaxhighlight lang="d">interface Camera {
// A virtual function.
Image takePhoto();
Line 171 ⟶ 175:
}
}
}</langsyntaxhighlight>
 
In addition, D's alias this feature allows one to create a type that, while it does not technically derive from two different classes, behaves as if it did.
 
<langsyntaxhighlight lang="d">class A {
string foo() {
return "I am an A.";
Line 212 ⟶ 216:
writeln(a.foo());
writeln(b.foo());
}</langsyntaxhighlight>
 
You can currently only have a single alias this, but multiple alias this is planned. Nested alias this works today, but is somewhat finicky.
Line 218 ⟶ 222:
Lastly, D has template and string mixins. These can be used for static polymorphism, where a piece of code is written once and has a single definition, but is used in multiple places. It does not enable any sort of dynamic polymorphism that is not covered above.
 
<langsyntaxhighlight lang="d">template registerable() {
void register() { /* implementation */ }
}
Line 236 ⟶ 240:
foo.register();
writeln(foo.myFunction());
}</langsyntaxhighlight>
 
Using D's [[Compile-time calculation|CTFE]] and [[reflection]] capabilities, string mixins can copy the interface of other types, and thus be used for proxies and mocks.
Line 243 ⟶ 247:
Delphi doesn't support multiple inheritance, but it does have multiple interfaces.
 
<syntaxhighlight lang="delphi">type
<lang Delphi>type
ICamera = Interface
// ICamera methods...
Line 254 ⟶ 258:
TCameraPhone = class(TInterfacedObject, ICamera, IMobilePhone)
// ICamera and IMobilePhone methods...
end;</langsyntaxhighlight>
 
=={{header|DWScript}}==
Line 271 ⟶ 275:
These shortcomings could be fixed if more powerful multiple inheritance were needed.
 
<langsyntaxhighlight lang="e">def minherit(self, supers) {
def forwarder match [verb, args] {
escape __return {
Line 293 ⟶ 297:
}
return forwarder
}</langsyntaxhighlight>
 
The task example:
 
<langsyntaxhighlight lang="e">def makeCamera(self) {
return def camera extends minherit(self, []) {
to takesPictures() { return true }
Line 319 ⟶ 323:
}
}
}</langsyntaxhighlight>
 
And testing that it works as intended:
 
<syntaxhighlight lang="e">
<lang e>
? def p := makeCameraPhone(p)
> [p.takesPictures(), p.makesCalls(), p.internalMemory()]
# value: [true, true, 33619968]</langsyntaxhighlight>
 
=={{header|Eiffel}}==
Having two class—one for CAMERA and the other for a MOBILE_PHONE ...
<langsyntaxhighlight lang="eiffel ">class
CAMERA
end</langsyntaxhighlight>
<langsyntaxhighlight lang="eiffel ">class
MOBILE_PHONE
end</langsyntaxhighlight>
=== Now Multiple Inherit ===
We can create a new CAMERA_PHONE, which inherits directly from both CAMERA and MOBILE_PHONE.
<langsyntaxhighlight lang="eiffel ">class
CAMERA_PHONE
inherit
CAMERA
MOBILE_PHONE
end</langsyntaxhighlight>
NOTE: There is no reasonable limit to the number of classes we can inherit from in a single class. The compiler helps us to navigate issues like repeated inheritance and the "diamond of death" easily and quickly.
 
=={{header|Elena}}==
ELENA only permits inheritance from one parent class. However, mixins are supported
<langsyntaxhighlight lang="elena">singleton CameraFeature
{
cameraMsg
Line 371 ⟶ 375:
console.writeLine(cp.cameraMsg);
console.writeLine(cp.mobileMsg)
}</langsyntaxhighlight>
Alternatively a group object may be created
<langsyntaxhighlight lang="elena">import system'dynamic;
 
class CameraFeature
Line 398 ⟶ 402:
console.writeLine(cp.cameraMsg);
console.writeLine(cp.mobileMsg)
}</langsyntaxhighlight>
 
=={{header|F_Sharp|F#}}==
A class can only inherit from one other class, but it can implement any number of interfaces.
 
<langsyntaxhighlight lang="fsharp">type Picture = System.Drawing.Bitmap // (a type synonym)
 
// an interface type
Line 424 ⟶ 428:
inherit MobilePhone()
interface Camera with
member x.takePicture() = new Picture(10, 10)</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">TUPLE: camera ;
TUPLE: mobile-phone ;
UNION: camera-phone camera mobile-phone ;</langsyntaxhighlight>
 
=={{header|Fantom}}==
Line 439 ⟶ 443:
It is an error for method names to conflict.
 
<langsyntaxhighlight lang="fantom">// a regular class
class Camera
{
Line 470 ⟶ 474:
echo (cp.mobileMsg)
}
}</langsyntaxhighlight>
 
 
Line 484 ⟶ 488:
following example code.
 
<langsyntaxhighlight lang="forth">
 
\ define class camera with method say:
Line 516 ⟶ 520:
\ output:
camera phone
</syntaxhighlight>
</lang>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
' FB does not currently support multiple inheritance. Composition has to be used instead if one wants
Line 536 ⟶ 540:
cam As Camera ' using composition here
' other stuff
End Type</langsyntaxhighlight>
 
=={{header|Go}}==
Go abandons traditional object oriented concepts of inheritance hierarchies, yet it does have features for composing both structs and interfaces.
<langsyntaxhighlight lang="go">// Example of composition of anonymous structs
package main
 
Line 570 ⟶ 574:
htc.sim = "XYZ"
fmt.Println(htc)
}</langsyntaxhighlight>
{{out}} (Note sensor field still blank)
<pre>{{zoom } {XYZ 3.14}}</pre>
<langsyntaxhighlight lang="go">// Example of composition of interfaces.
// Types implement interfaces simply by implementing functions.
// The type does not explicitly declare the interfaces it implements.
Line 619 ⟶ 623:
i.photo()
i.call()
}</langsyntaxhighlight>
{{out}}
<pre>
Line 630 ⟶ 634:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">class Camera a
class MobilePhone a
class (Camera a, MobilePhone a) => CameraPhone a</langsyntaxhighlight>
 
==Icon and {{header|Unicon}}==
Line 641 ⟶ 645:
This became one of the major addons contributing to Unicon.
 
<langsyntaxhighlight lang="unicon">class Camera (instanceVars)
# methods...
# initializer...
Line 654 ⟶ 658:
# methods...
# initialiser...
end</langsyntaxhighlight>
 
=={{header|Io}}==
<langsyntaxhighlight Iolang="io">Camera := Object clone
Camera click := method("Taking snapshot" println)
 
Line 668 ⟶ 672:
myPhone := CameraPhone clone
myPhone click // --> "Taking snapshot"
myPhone call // --> "Calling home"</langsyntaxhighlight>
In Io each object has an internal list of prototype objects it inherits from. You can add to this list with <code>appendProto</code>.
 
=={{header|Ioke}}==
<langsyntaxhighlight lang="ioke">Camera = Origin mimic
MobilePhone = Origin mimic
CameraPhone = Camera mimic mimic!(MobilePhone)</langsyntaxhighlight>
 
=={{header|J}}==
<langsyntaxhighlight lang="j">coclass 'Camera'
 
create=: verb define
Line 708 ⟶ 712:
destroy=: codestroy
 
NB. additional camera-phone methods go here</langsyntaxhighlight>
The adverb Fix (f.) is needed as shown so the superclass constructors
get executed in the object, not in the superclass.
Line 715 ⟶ 719:
Java does not allow multiple inheritance, but you can "implement" multiple interfaces. All methods in interfaces are abstract (they don't have an implementation).
When you implement an interface you need to implement the specified methods.
<langsyntaxhighlight lang="java">public interface Camera{
//functions here with no definition...
//ex:
//public void takePicture();
}</langsyntaxhighlight>
<langsyntaxhighlight lang="java">public interface MobilePhone{
//functions here with no definition...
//ex:
//public void makeCall();
}</langsyntaxhighlight>
<langsyntaxhighlight lang="java">public class CameraPhone implements Camera, MobilePhone{
//functions here...
}</langsyntaxhighlight>
 
{{omit|Julia}}
Line 733 ⟶ 737:
=={{header|Julia}}==
 
Julia supports inheritance via abstract types. In Julia, multiple dispatch allows objects of different types to have the same function interfaces. Julia also can support traits via parameters in type declarations or with macros. This makes multiple inheritance in Julia mostly unnecessary, except for the inconvenience of composing the data in a mixed type when declaring multiple similar types, for which there are macros.<br /> <br />For example, the functions <code> dialnumber(equipment, name) </code> and <code> video(equipment, filename) </code> could be used as generic interfaces to implement methods for a <code>Telephone</code>, a <code>Camera</code>, and a <code>SmartPhone</code>, and Julia would dispatch according to the type of the equipment.<langsyntaxhighlight lang="julia">
abstract type Phone end
 
Line 769 ⟶ 773:
dialnumber(dphone)
dialnumber(cphone)
</langsyntaxhighlight>{{output}}<pre>
tat tat tat tat
beep beep
Line 779 ⟶ 783:
to be abstract or to provide accessor implementations.
 
<langsyntaxhighlight lang="scala">interface Camera {
val numberOfLenses : Int
}
Line 806 ⟶ 810:
println(c2)
println(listOf(c2.javaClass.superclass) + c2.javaClass.interfaces)
}</langsyntaxhighlight>
{{out}}
<pre>CameraPhone(numberOfLenses=1, battery_level=50)
Line 820 ⟶ 824:
and trays hand down the methods it has implemented provided that the type
fulfills the requirements for the trait. [http://lassoguide.com/language/traits.html http://lassoguide.com/language/traits.html]
<langsyntaxhighlight Lassolang="lasso">define trait_camera => trait {
require zoomfactor
 
Line 856 ⟶ 860:
#mydevice -> has_zoom
'<br />'
#mydevice -> is_smart</langsyntaxhighlight>
-> false
 
Line 865 ⟶ 869:
Latitude is a prototype-oriented language, and every object can have only one prototype. As such, multiple inheritance in the usual sense is impossible in Latitude. The behavior of multiple (implementation) inheritance can be approximated with mixins.
 
<langsyntaxhighlight lang="latitude">Camera ::= Mixin clone.
MobilePhone ::= Mixin clone.
 
CameraPhone ::= Object clone.
Camera inject: CameraPhone.
MobilePhone inject: CameraPhone.</langsyntaxhighlight>
 
In order to add functionality to either of the mixins, the <code>interface</code> slot of the mixin must be modified to include the name of the new method. Injecting a mixin makes a copy of the methods, as opposed to traditional (prototype) inheritance in which method calls are delegated.
Line 876 ⟶ 880:
=={{header|Lingo}}==
Lingo does not support multiple inheritance. But its slightly idiosyncratic inheritance implementation based on "ancestors" allows to assign/change inheritance relations at runtime. So a similar (but not identical) effect can be achieved by something like this:
<langsyntaxhighlight lang="lingo">-- parent script "Camera"
property resolution
 
Line 886 ⟶ 890:
on snap (me)
put "SNAP!"
end</langsyntaxhighlight>
 
<langsyntaxhighlight lang="lingo">-- parent script "MobilePhone"
property ringtone
 
Line 900 ⟶ 904:
put "RING!!!"
end repeat
end</langsyntaxhighlight>
 
<langsyntaxhighlight lang="lingo">-- parent script "CameraPhone"
property ancestor
 
Line 916 ⟶ 920:
 
return me
end</langsyntaxhighlight>
 
Usage:
<langsyntaxhighlight lang="lingo">cp = script("CameraPhone").new()
 
cp.snap()
Line 933 ⟶ 937:
 
put cp.ringtone
-- "Bell"</langsyntaxhighlight>
 
=={{header|Logtalk}}==
Line 939 ⟶ 943:
There is no "class" keyword in Logtalk;
an "object" keyword is used instead (Logtalk objects play the role of classes, meta-classes, instances, or prototypes depending on the relations with other objects).
<langsyntaxhighlight lang="logtalk">:- object(camera,
...).
...
:- end_object.</langsyntaxhighlight>
 
<langsyntaxhighlight lang="logtalk">:- object(mobile_phone,
...).
...
:- end_object.</langsyntaxhighlight>
 
<langsyntaxhighlight lang="logtalk">:- object(camera_phone,
specializes(camera, mobile_phone),
...).
...
:- end_object.</langsyntaxhighlight>
 
=={{header|Lua}}==
Line 960 ⟶ 964:
by making it a closure.
 
<langsyntaxhighlight lang="lua">function setmetatables(t,mts) --takes a table and a list of metatables
return setmetatable(t,{__index = function(self, k)
--collisions are resolved in this implementation by simply taking the first one that comes along.
Line 972 ⟶ 976:
camera = {}
mobilephone = {}
cameraphone = setemetatables({},{camera,mobilephone})</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Class Camera {
Line 1,021 ⟶ 1,025:
}
CheckIt
</syntaxhighlight>
</lang>
 
=={{header|Nemerle}}==
Like C#, Nemerle only allows pseudo-multiple inheritance through interfaces.
In Nemerle, the base class must be listed before any interfaces.
<langsyntaxhighlight lang="nemerle">interface ICamera {
// ...
}
Line 1,036 ⟶ 1,040:
class CameraPhone: MobilePhone, ICamera {
// ...
}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
Line 1,045 ⟶ 1,049:
In this sample the class/interface names are augmented over those required in the task to prevent namespace pollution.
The sample also provides a complete working implementation to demonstrate the capability.
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
 
Line 1,090 ⟶ 1,094:
return shutter
method call() public
return ringTone</langsyntaxhighlight>
{{out}}
<pre>
Line 1,100 ⟶ 1,104:
=={{header|Nim}}==
nim does not support multiple inheritance (version<=1.4.6). It is just a demonstration of the procedure reloading nature of nim code.
<langsyntaxhighlight lang="nim">type
Camera = ref object of RootObj
MobilePhone = ref object of RootObj
Line 1,112 ⟶ 1,116:
var cp: CameraPhone
echo(cp is Camera)
echo(cp is MobilePhone)</langsyntaxhighlight>
{{out}}
<pre>
Line 1,127 ⟶ 1,131:
of multiple classes, you can use message forwarding to mimic the functionality of those classes without actually inheriting them, as described in [http://support.apple.com/kb/TA45894 this guide]:
 
<langsyntaxhighlight lang="objc">@interface Camera : NSObject {
}
@end
Line 1,179 ⟶ 1,183:
}
 
@end</langsyntaxhighlight>
 
Caveat: the CameraPhone class will still technically not inherit from
Line 1,185 ⟶ 1,189:
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">class camera =
object (self)
(*functions go here...*)
end</langsyntaxhighlight>
<langsyntaxhighlight lang="ocaml">class mobile_phone =
object (self)
(*functions go here...*)
end</langsyntaxhighlight>
<langsyntaxhighlight lang="ocaml">class camera_phone =
object (self)
inherit camera
inherit mobile_phone
(*functions go here...*)
end</langsyntaxhighlight>
 
=={{header|Oforth}}==
Line 1,209 ⟶ 1,213:
If Camera and MobilePhone are designed as properties, we can write :
 
<langsyntaxhighlight Oforthlang="oforth">Property new: Camera
Property new: MobilePhone
 
Object Class new: CameraPhone
CameraPhone is: Camera
CameraPhone is: MobilePhone</langsyntaxhighlight>
 
=={{header|ooRexx}}==
Line 1,220 ⟶ 1,224:
Mixins are more than just interfaces.
They can contain concrete method implementations and also create instance variables (scoped as private variables to the mixin methods).
<syntaxhighlight lang="oorexx">
<lang ooRexx>
-- inherited classes must be created as mixinclasses.
::class phone mixinclass object
Line 1,234 ⟶ 1,238:
-- or
 
::class cameraphone2 subclass camera inherit phone</langsyntaxhighlight>
 
=={{header|OxygenBasic}}==
<langsyntaxhighlight lang="oxygenbasic">class Camera
string cbuf
method TakePhoto()
Line 1,260 ⟶ 1,264:
 
cp.ViewPhoto
cp.MakeCall</langsyntaxhighlight>
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">class Camera end
 
class MobilePhone end
 
class CameraPhone from Camera MobilePhone end</langsyntaxhighlight>
 
=={{header|Pascal}}==
Line 1,273 ⟶ 1,277:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">package Camera;
#functions go here...
1;</langsyntaxhighlight>
 
<langsyntaxhighlight lang="perl">package MobilePhone;
#functions go here...
1;</langsyntaxhighlight>
 
<langsyntaxhighlight lang="perl">package CameraPhone;
use Camera;
use MobilePhone;
@ISA = qw( Camera MobilePhone );
#functions go here...
1;</langsyntaxhighlight>
 
or
 
<langsyntaxhighlight lang="perl">package CameraPhone;
use base qw/Camera MobilePhone/;
#functions go here...</langsyntaxhighlight>
 
The same using the [http://search.cpan.org/perldoc?MooseX::Declare MooseX::Declare] extention:
<langsyntaxhighlight lang="perl">use MooseX::Declare;
 
class Camera {
Line 1,305 ⟶ 1,309:
class CameraPhone extends(Camera, MobilePhone) {
# methods ...
}</langsyntaxhighlight>
 
=={{header|Phix}}==
Line 1,312 ⟶ 1,316:
===inheritance===
The programmer is expected to assume complete responsibility (away from the compiler) for checking/resolving any conflicts.
<syntaxhighlight lang="phix">
<lang Phix>
class Camra
string name = "nikkon"
Line 1,324 ⟶ 1,328:
end class
CamraPhone cp = new()
cp.show()</langsyntaxhighlight>
{{out}}
<pre>
Line 1,334 ⟶ 1,338:
Note that invoking new() inside a class definition creates shared references to a single instance.<br>
The compiler demands to be explicitly told what the inner/inlined new() on cp2 are actually for.
<langsyntaxhighlight Phixlang="phix">class Camera
public string name = "nikkon"
end class
Line 1,356 ⟶ 1,360:
cp1.show()
cp2.show()
cp3.show() -- crashes without internal/above new()</langsyntaxhighlight>
{{out}}
<pre>
Line 1,365 ⟶ 1,369:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(class +Camera)
(class +MobilePhone)
 
(class +CameraPhone +MobilePhone +Camera)</lang>
</syntaxhighlight>
 
=={{header|Pop11}}==
<langsyntaxhighlight lang="pop11">;;; load object support
lib objectclass;
 
Line 1,385 ⟶ 1,390:
enddefine;
 
;;; methods go here</langsyntaxhighlight>
 
=={{header|PowerShell}}==
{{works with|PowerShell|5}}
<syntaxhighlight lang="powershell">
<lang PowerShell>
class Camera {}
class MobilePhone {}
class CameraPhone : Camera, MobilePhone {}
</syntaxhighlight>
</lang>
 
=={{header|PureBasic}}==
Using the open-source precompiler [http://www.development-lounge.de/viewtopic.php?t=5915 SimpleOOP].
<langsyntaxhighlight PureBasiclang="purebasic">Class Camera
EndClass
 
Line 1,404 ⟶ 1,409:
 
Class CameraMobile Extends Camera Extends Mobil
EndClass</langsyntaxhighlight>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">class Camera:
pass #functions go here...</langsyntaxhighlight>
 
<langsyntaxhighlight lang="python">class MobilePhone:
pass #functions go here...</langsyntaxhighlight>
 
<langsyntaxhighlight lang="python">class CameraPhone(Camera, MobilePhone):
pass #functions go here...</langsyntaxhighlight>
 
=={{header|Racket}}==
Line 1,421 ⟶ 1,426:
Mixins can be used to achieve some of the benefits of multiple inheritance.
 
<langsyntaxhighlight lang="racket">#lang racket
 
(define camera<%> (interface ()))
Line 1,430 ⟶ 1,435:
(super-new)
;; implement methods here
))</langsyntaxhighlight>
 
=={{header|Raku}}==
Line 1,436 ⟶ 1,441:
 
{{works with|Rakudo|2012.06}}
<syntaxhighlight lang="raku" perl6line>class Camera {}
class MobilePhone {}
class CameraPhone is Camera is MobilePhone {}
 
say CameraPhone.^mro; # undefined type object
say CameraPhone.new.^mro; # instantiated object</langsyntaxhighlight>
{{out}}
<pre>CameraPhone() Camera() MobilePhone() Any() Mu()
Line 1,451 ⟶ 1,456:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Inheritance/Multiple
 
Line 1,486 ⟶ 1,491:
# Add MobilePhone Attributes
AddParentClassAttributes(self,:MobilePhone)
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,497 ⟶ 1,502:
=={{header|Ruby}}==
Ruby does not have multiple inheritance, but you can mix modules into classes:
<langsyntaxhighlight lang="ruby">module Camera
# define methods here
end
Line 1,506 ⟶ 1,511:
include Camera
# define methods here
end</langsyntaxhighlight>
 
=={{header|Rust}}==
<langsyntaxhighlight Rustlang="rust">trait Camera {}
trait MobilePhone {}
trait CameraPhone: Camera + MobilePhone {}</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">trait Camera
trait MobilePhone
class CameraPhone extends Camera with MobilePhone</langsyntaxhighlight>
 
=={{header|Self}}==
Self is a class-free, object-oriented language, and as such, it uses prototypal inheritance instead of classical inheritance. This is an example of the relevant excerpts from a Self transporter fileout. Normally the object tree would be built and navigated within the graphical Self environment.
<langsyntaxhighlight lang="self">camera = ()</langsyntaxhighlight>
<langsyntaxhighlight lang="self">mobilePhone = ()</langsyntaxhighlight>
<langsyntaxhighlight lang="self">cameraPhone = (| cameraParent* = camera. mobilePhoneParent* = mobilePhone |)</langsyntaxhighlight>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">class Camera {};
class MobilePhone {};
class CameraPhone << Camera, MobilePhone {};</langsyntaxhighlight>
 
=={{header|Slate}}==
<langsyntaxhighlight lang="slate">define: #Camera.
define: #MobilePhone.
define: #CameraPhone &parents: {Camera. MobilePhone}.</langsyntaxhighlight>
 
=={{header|Swift}}==
Like Objective-C, Swift does not allow multiple inheritance. However, you can conform to multiple protocols.
<langsyntaxhighlight Swiftlang="swift">protocol Camera {
}
Line 1,547 ⟶ 1,552:
class CameraPhone: Camera, Phone {
}</langsyntaxhighlight>
 
=={{header|Tcl}}==
{{works with|Tcl|8.6}} or {{libheader|TclOO}}
<langsyntaxhighlight lang="tcl">package require TclOO
 
oo::class create Camera
Line 1,557 ⟶ 1,562:
oo::class create CameraPhone {
superclass Camera MobilePhone
}</langsyntaxhighlight>
 
=={{header|Wren}}==
Line 1,563 ⟶ 1,568:
 
However, multiple inheritance can be simulated by inheriting from a single class and then embedding objects of other classes and wrapping their methods.
<langsyntaxhighlight ecmascriptlang="wren">class Camera {
construct new() {}
snap() { System.print("taking a photo") }
Line 1,583 ⟶ 1,588:
var cp = CameraPhone.new(p)
cp.snap()
cp.call()</langsyntaxhighlight>
 
{{out}}
Line 1,592 ⟶ 1,597:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">class Camera{} class MobilePhone{}
class CameraPhone(Camera,MobilePhone){}
CameraPhone.linearizeParents</langsyntaxhighlight>
{{out}}Show the class search order
<pre>L(Class(CameraPhone),Class(Camera),Class(MobilePhone))</pre>
 
{{omit from|6502 Assembly}}
{{omit from|68000 Assembly}}
{{omit from|8080 Assembly}}
{{omit from|8086 Assembly}}
{{omit from|ARM Assembly}}
{{omit from|AWK}}
{{omit from|Axe}}
{{omit from|Batch File|Not an OO language.}}
{{omit from|JavaScript|https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Property_Inheritance_Revisited/No_Multiple_Inheritance}}
Line 1,610 ⟶ 1,621:
{{omit from|TI-83 BASIC|Does not have user-defined data structures or objects.}}
{{omit from|TI-89 BASIC|Does not have user-defined data structures or objects.}}
{{omit from|AxeZ80 Assembly}}
9,479

edits