This articledoes notcite anysources. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged andremoved. Find sources: "Comparison of programming languages" object-oriented programming – news ·newspapers ·books ·scholar ·JSTOR(November 2025) (Learn how and when to remove this message) |
Thiscomparison of programming languages compares howobject-oriented programming languages such asC++,Java,Smalltalk,Object Pascal,Perl,Python, and others manipulatedata structures.
| construction | destruction | |
|---|---|---|
| ABAP Objects | data variabletype ref to class.[1] | [2][3] |
| APL (Dyalog) | variable←⎕NEW class «parameters» | ⎕EX 'variable' |
| C++ | class variable«(parameters)»;[4] orclass* variable=newclass«(parameters)»;[5] | delete pointer; |
| C# | class variable= new class(parameters); | variable.Dispose();[3] |
| Java | [3] | |
| D | destroy(variable); | |
| eC | class «instance handle»{ «properties/data members assignments, instance method overrides»} | delete instance handle; |
| Objective-C (Cocoa) | class*variable= [[class alloc ] init]; orclass*variable= [[class alloc ]initWithFoo:parameter «bar:parameter ...»]; | [variablerelease]; |
| Swift | let variable= class(parameters) | |
| Python | variable= class(parameters) | del variable[3] (Normally not needed) |
| Visual Basic .NET | Dim variableAs New class(parameters) | variable.Dispose()[3] |
| Xojo | Dim variableAs New class(parameters) | variable =Nil |
| Eiffel | create variable orcreate «{TYPE}» variable.make_foo «(parameters)» orvariable:= create{TYPE} orvariable:= create {TYPE}.make_foo «(parameters)» | [3] |
| PHP | $variable= new class«(parameters)»; | unset($variable);[3] |
| Perl 5 | «my»$variable= class->new«(parameters)»; | undef($variable); |
| Raku | «my»$variable= class.new«(parameters)»; | $variable.undefine; |
| Ruby | variable= class.new«(parameters)» | [3] |
| Windows PowerShell | $variable= New-Object«-TypeName» class ««-ArgumentList» parameters» | Remove-Variable «-Name» variable |
| OCaml | let variable= new class «parameters» orlet variable= object membersend[6] | [3] |
| F# | let variable=«new »class(«parameters») | |
| Smalltalk | The class is an Object. Just send a message to a class, usually #new or#new:, and many others, for example:Pointx:10y:20.Arraywith:-1with:3with:2. | |
| JavaScript | var variable= new class«(parameters)» orvar variable= { «key1: value1«, key2: value2 ...»»} | [3] |
| Object Pascal (Delphi) | ClassVar:= ClassType.ConstructorName(parameters); | ClassVar.Free; |
| Scala | valobj=newObject// no parametersvalobj=newObject(arg0,arg1,arg2...)valobj=Object(arg0,arg1,arg2...)// case classvalobj=newObject(arg0,arg1,param1=value1,...)// named parameters | [3] |
| COBOL | INVOKE class"NEW"RETURNING variable orMOVE class::"NEW"TO variable | |
| Cobra | variable «as class»= class(parameters) | variable.dispose |
| ISLISP | (setq variable (create (class <some-class> [:field-1 value-1 [:field-2 value-2] ..]))) | [3] |
| class | protocol | namespace | |
|---|---|---|---|
| ABAP Objects | class namedefinition «inheriting from parentclass». «interfaces: interfaces.» method_and_field_declarationsendclass. | interface name. membersendinterface. | N/a |
| APL (Dyalog) | :Class name «:parentclass» «,interfaces»members:EndClass | :Interface namemembers:EndInterface | :Namespace namemembers:EndNamespace |
| C++ | classname« : publicparentclasses[7]» {members }; | namespacename {members } | |
| C# | classname« :«parentclass»«, interfaces»» {members } | interface name« : parentinterfaces»{ members} | |
| D | modulename; | ||
| eC | class name« : base class»{ «default member values assignments» «members»} | | namespace name; |
| Java | classname« extendsparentclass»« implementsinterfaces» {members } | interface name« extends parentinterfaces»{ members} | packagename; members |
| PHP | namespacename;members | ||
| Objective-C | @interfacename« :parentclass»[8]«< protocols>» {instance_fields }method_and_property_declarations @end[9] | @protocolname«< parentprotocols>» members @end | [10] |
| Swift | classname« :«parentclass»«, protocols»» {members } | protocolname« :parentprotocols» {members } | |
| Python | classname«(parentclasses[7])»: | [11] | __all__ = [member1,member2,... ] |
| Visual Basic .NET | Classname« Inheritsparentclass»« Implementsinterfaces» | Interfacename« Inheritsparentinterfaces» | Namespacename |
| Xojo | Classname« Inheritsparentclass»« Implementsinterfaces» | Interfacename« Inheritsparentinterfaces» | Modulename |
| Eiffel | classname« inheritparentclasses[7]» | N/a | |
| Perl | packagename;«@ISA = qw(parentclasses[7]);» members1; | packagename; members | |
| Raku | classname «is parentclass «is parentclass ...[7]»» «does role «does role ...»»{ members} | rolename «does role «does role ...»»{ members} | module name{ members} |
| Ruby | classname« < parentclass» | modulename | |
| Windows PowerShell | N/a | ||
| OCaml | classname «parameters» = object«(self)» «inheritparentclass «parameters» «inheritparentclass «parameters» ...[7]»» membersend | module name | |
| F# | typename«(parameters)»«as this»= class «inheritparentclass«(parameters)» «as base»» members «interface interfacewith implementation «interface interfacewith implementation ...»»end | typename= interface membersend | namespace name |
| Smalltalk | [12] | [13] | |
| JavaScript (ES6) | class name «extends parentclass»{ members} | ||
| Object Pascal (Delphi) | ClassName = Class «(ClassParent, Interfaces)» | packagename; members | |
| Scala | classConcreteClass(constructorparams)extendsParentClasswithTrait1withTrait2withTrait2{// members} | traitTraitNameextendsOtherTrait1withOtherTrait2withOtherTrait3{// members} | packagename |
| COBOL | CLASS-ID. name« INHERITS« FROM» parentclasses».FACTORY« IMPLEMENTS interfaces».class-membersEND FACTORY.OBJECT« IMPLEMENTS interfaces».instance-membersEND OBJECT.
| INTERFACE-ID. name« INHERITS« FROM» interfaces».members
| N/a |
| Cobra | class name «inherits parentclass» «implements interfaces» | interface name «inherits parentinterfaces» | namespace name |
| ISLISP | (defclass name (base-class) ((x:initform 0:accessor get-x:initarg x)) (:abstractp nil)) | ||
| constructor | destructor | finalizer[14] | |
|---|---|---|---|
| ABAP Objects | methods constructor «importing parameter = argument»[15] | N/a | |
| APL (Dyalog) | ∇ name:Implements Constructor «:Base «expr»»instructions∇ | ∇ name:Implements Destructorinstructions∇ | |
| C++ | class(«parameters»)«:initializers[16]» {instructions } | ~class() {instructions } | |
| C# | class(«parameters») {instructions } | void Dispose(){instructions } | ~class() {instructions } |
| D | this(«parameters») {instructions } | ~this() {instructions } | |
| eC | class() { instructions} | ~class() { instructions} | |
| Java | class(«parameters») {instructions } | void finalize() {instructions } | |
| Eiffel | [17] | [18] | |
| Objective-C (Cocoa) | | | |
| Swift | init(«parameters») {instructions } | deinit {instructions } | |
| Python | | | |
| Visual Basic .NET | | | |
| Xojo | Sub Constructor(«parameters») | Sub Destructor() | |
| PHP | | | |
| Perl | | | |
| Raku | | | |
| Ruby | def initialize«(parameters)» | N/a | |
| Windows PowerShell | N/a | ||
| OCaml | initializer instructions[19] | N/a | |
| F# | do instructions or[20] | | |
| JavaScript | function name(«parameters»){ instructions}[21] | N/a | |
| JavaScript (ES6) | constructor(«parameters») { instructions} | ||
| COBOL | N/a[22] | N/a | |
| Cobra | cue init(parameters) | def dispose | |
| ISLISP | (defmethod initialize-object ((instance <class-name>) initvalues) | ||
| public | private | protected | friend | |
|---|---|---|---|---|
| ABAP Objects | public section.[23] data fieldtype type. | private section.[23] data fieldtype type. | protected section.[23] data fieldtype type. | [24] |
| APL (Dyalog) | :Field Public field «← value» | :Field «Private» field «← value» | ||
| C++ | public:type field; | private:type field; | protected:type field; | [25] |
| C# | publictype field «= value»; | privatetype field «= value»; | protectedtype field «= value»; | internal type field «= value»; |
| D | package type field «= value»; | |||
| Java | protectedtype field «= value»; | type field «= value»; | ||
| eC | public type field; | private type field; | ||
| Eiffel | feature | feature {NONE} | feature {current_class} | feature {FRIEND} |
| Objective-C | @publictype field; | @privatetype field; | @protectedtype field; | @packagetype field; |
| Swift | N/a | |||
| Smalltalk | N/a | [26] | N/a | |
| Python | self.field =value[27] | N/a[28] | N/a | |
| Visual Basic .NET | Publicfield Astype «= value» | Privatefield Astype «= value» | Protectedfield Astype «= value» | Friendfield Astype «= value» |
| Xojo | Publicfield Astype «= value» | Privatefield Astype «= value» | Protectedfield Astype «= value» | N/a |
| PHP | public $field «= value»; | private $field «= value»; | protected $field «= value»; | |
| Perl | $self->{field} =value;[27] | N/a | ||
| Raku | has« type »$.field« is rw» | has« type »$!field | N/a | |
| Ruby | N/a | @field= value[27] | ||
| Windows PowerShell | Add-Member | N/a | ||
| OCaml | N/a | val «mutable» field= value | N/a | |
| F# | N/a | let «mutable» field= value | N/a | |
| JavaScript | this.field =value[27] | |||
| COBOL | N/a | level-number field clauses.[29] | N/a | N/a |
| Cobra | var field «as type» «= value» | var__field «as type» «= value» | var_field «as type» «= value» | |
| ISLISP | (field:initform value:accessor accessor-name:initarg keyword) | |||
| basic/void method | value-returning method | ||
|---|---|---|---|
| ABAP Objects | methods name «importing parameter = argument» «exporting parameter = argument» «changing parameter = argument» «returning value(parameter)»[30] | [31] | |
| APL (Dyalog) | ∇ «left argument» name «right arguments»instructions∇ | ∇ result← «left argument» name «right arguments»instructions∇ | |
C++[32]
The implementation of methods is usually provided in a separate source file, with the following syntax
| voidfoo(«parameters») {instructions } | type foo(«parameters») {instructions ...return value; } | |
| C# | |||
| D | |||
| Java | |||
| eC | void««type of 'this'»::»foo(«parameters») {instructions } | type ««type of this»::»foo(«parameters») {instructions ...return value; } | |
| Eiffel | foo( «parameters») | foo( «parameters»): TYPE | |
| Objective-C | - (void)foo«:parameter «bar:parameter ...»» {instructions } | - (type)foo«:parameter «bar:parameter ...»» {instructions...return value; } | |
| Swift | funcfoo(«parameters») {instructions } | funcfoo(«parameters») ->type {instructions...return value } | |
| Python | deffoo(self«, parameters»): | deffoo(self«, parameters»): | |
| Visual Basic .NET | SubFoo(«parameters») | FunctionFoo(«parameters») Astype | |
| Xojo | SubFoo(«parameters») | FunctionFoo(«parameters») Astype | |
| PHP | functionfoo(«parameters»)«: void» {instructions } | functionfoo(«parameters»)«:type» {instructions ...return value; } | |
| Perl | subfoo { my ($self«,parameters») = @_;instructions } | subfoo { my ($self«,parameters») = @_;instructions ...return value; } | |
| Raku | «has »«multi »methodfoo(««$self: »parameters») {instructions } | «has «type »»«multi »methodfoo(««$self: »parameters») {instructions ...return value; } | |
| Ruby | deffoo«(parameters)» | deffoo«(parameters)» | |
| Windows PowerShell | Add-Member«-MemberType» ScriptMethod«-Name» foo «-Value» {«param(parameters)»instructions } -InputObjectvariable | Add-Member«-MemberType» ScriptMethod«-Name» foo «-Value» {«param(parameters)»instructions ...return value} -InputObjectvariable | |
| OCaml | N/a | method foo «parameters»= expression | |
| F# | member this.foo(«parameters») = expression | ||
| JavaScript | this.method = function(«parameters») {instructions}[34] | this.method = function(«parameters») {instructions...return value;}[34] | |
| Javascript (ES6) | foo(«parameters») {instructions} | foo(«parameters») {instructions...return value;} | |
| COBOL | METHOD-ID. foo.instructions
| METHOD-ID. foo.instructions
| |
| Cobra | def foo(parameters) | def foo(parameters) as type | |
| ISLISP | (defgeneric method (arg1 arg2)) |
How to declare a property named "Bar"
| read-write | read-only | write-only | |
|---|---|---|---|
| ABAP Objects | N/a | ||
| APL (Dyalog) | :Property Bar∇ result← Getinstructions∇∇ Set argumentsinstructions∇:EndProperty Bar | :Property Bar∇ result← Getinstructions∇:EndProperty Bar | :Property Bar∇ Set argumentsinstructions∇:EndProperty Bar |
| C++ | N/a | ||
| C# | type Bar{ | type Bar{ get {instructions ...returnvalue;} } | type Bar{ set {instructions } } |
| D | @property type bar() {instructions ...returnvalue;} | @property type bar() {instructions ...returnvalue;} | @property type bar(type value) {instructions ...returnvalue;} |
| eC | property type Bar{ | property type Bar{ get {instructions ...returnvalue;} } | property type Bar{ set {instructions } } |
| Java | N/a | ||
| Objective-C 2.0 (Cocoa) | @property (readwrite) type bar; and then inside@implementation | @property (readonly) type bar; and then inside@implementation | N/a |
| Swift | var bar: type{ get {instructions } set«(newBar)» {instructions } } | var bar: type{instructions } | N/a |
| Eiffel | feature -- Access | ||
| Python | def setBar(self,value):[35] | def getBar(self): | def setBar(self,value): |
| Visual Basic .NET | PropertyBar() Astype | ReadOnly PropertyBar() Astype | WriteOnly PropertyBar() Astype |
| Xojo | ComputedPropertyBar() Astype | ComputedPropertyBar() Astype | ComputedPropertyBar() Astype |
| PHP | function __get($property) { | function __get($property) { | function __set($property,$value) { |
| Perl | sub Bar { | sub Bar { | sub Bar { |
| Raku | N/a | ||
| Ruby | defbar | defbar | defbar=(value) |
| Windows PowerShell | Add-Member | Add-Member | Add-Member |
| OCaml | N/a | ||
| F# | member this.Barwith get() = expressionand set(value) = expression | member this.Bar= expression | member this.Barwith set(value) = expression |
| JavaScript (ES6) | get bar(«parameters»){ instructions ...returnvalue}setbar(«parameters») {instructions} | get bar(«parameters»){ instructions ...returnvalue} | setbar(«parameters») {instructions} |
| COBOL | METHOD-ID. GET PROPERTY bar.instructions
instructions
| METHOD-ID. GET PROPERTY bar.instructions
| METHOD-ID. SET PROPERTY bar.instructions
|
| Cobra | pro bar «as type» | get bar «as type» | set bar «as type» |
| ISLISP | N/a | ||
| read-write | read-only | write-only | |
|---|---|---|---|
| ABAP Objects | N/a | ||
| C++ | N/a | ||
| C# | type Bar{ get; set; } | type Bar{ get; private set; } | type Bar{ private get; set; } |
| D | N/a | ||
| Java | N/a | ||
| Objective-C 2.0 (Cocoa) | @property (readwrite) type bar;and then inside@implementation | @property (readonly) type bar;and then inside@implementation | N/a |
| Swift | var bar: type | let bar: type | N/a |
| Eiffel | |||
| Python | @property | @property | bar= property() |
| Visual Basic .NET | Property BarAs type« = initial_value» (VB 10) | ||
| PHP | |||
| Perl[36] | usebaseqw(Class::Accessor); | usebaseqw(Class::Accessor); | usebaseqw(Class::Accessor); |
| Raku | N/a | ||
| Ruby | attr_accessor :bar | attr_reader :bar | attr_writer :bar |
| Windows PowerShell | |||
| OCaml | N/a | ||
| F# | member val Bar= valuewith get, set | ||
| COBOL | level-number bar clausesPROPERTY. | level-number bar clausesPROPERTY «WITH» NO SET. | level-number bar clausesPROPERTY «WITH» NO GET. |
| Cobra | pro barfrom var «as type» | get barfrom var «as type» | set barfrom var «as type» |
| unary | binary | function call | |
|---|---|---|---|
| ABAP Objects | N/a | ||
| C++ | typeoperator symbol() {instructions } | typeoperator symbol(type operand2) {instructions } | typeoperator () («parameters») {instructions } |
| C# | statictype operatorsymbol(type operand) {instructions } | statictype operatorsymbol(type operand1,type operand2) {instructions } | N/a |
| D | typeopUnary(string s)() if (s == "symbol") {instructions } | typeopBinary(string s)(type operand2) if (s == "symbol") {instructions } | typeopCall(«parameters») {instructions } |
| Java | N/a | ||
| Objective-C | |||
| Swift | func symbol(operand1: type) ->returntype {instructions } (outside class) | func symbol(operand1: type1,operand2: type2) ->returntype {instructions } (outside class) | |
| Eiffel[37] | op_namealias "symbol": TYPE | op_namealias "symbol" (operand: TYPE1): TYPE2 | |
| Python | def __opname__(self): | def __opname__(self,operand2): | def __call__(self«,parameters»): |
| Visual Basic .NET | Shared Operatorsymbol(operand Astype) Astype | Shared Operatorsymbol(operand1 Astype,operand2 Astype) Astype | N/a |
| Xojo | Function Operator_name(operand Astype) Astype | N/a | |
| PHP | [38] | function __invoke(«parameters») {instructions } (PHP 5.3+) | |
| Perl | use overload "symbol" | use overload "symbol" | |
| Raku | «our «type »»«multi »method prefix:<symbol> («$operand: ») { instructions ...returnvalue;} or | «our «type »»«multi »method infix:<symbol> («$operand1: » type operand2) { instructions ...returnvalue;} | «our «type »»«multi » |
| Ruby | defsymbol | defsymbol(operand2) | N/a |
| Windows PowerShell | N/a | ||
| OCaml | |||
| F# | static member (symbol) operand= expression | static member (symbol)(operand1, operand2) = expression | N/a |
| COBOL | N/a | ||
| ISLISP | N/a | ||
| read-write | read-only | write-only | |
|---|---|---|---|
| ABAP Objects | N/a | ||
| APL (Dyalog) | :Property Numbered Default name∇ result← Getinstructions∇∇ Set argumentsinstructions∇:EndProperty Bar | :Property Numbered Default Bar∇ result← Getinstructions∇:EndProperty Bar | :Property Numbered Default Bar∇ Set argumentsinstructions∇:EndProperty Bar |
| C++ | type& operator[](type index) {instructions } | typeoperator[](type index) {instructions } | |
| C# | typethis[type index] { | typethis[type index] { get{instructions } } | typethis[type index] { set{instructions } } |
| D | typeopIndex(type index) {instructions } | typeopIndex(type index) {instructions } | typeopIndexAssign(type value,type index) {instructions } |
| Java | N/a | ||
| Objective-C (recent Clang compiler) | N/a | | |
| Swift | subscript (index :type) ->returntype { get {instructions } set«(newIndex)» {instructions } } | subscript (index :type) ->returntype {instructions } | |
| Eiffel[37] | bracket_namealias "[]" (index: TYPE): TYPEassign set_item | bracket_namealias "[]" (index: TYPE): TYPE | |
| Python | def __getitem__(self,index): | def __getitem__(self,index): | def __setitem__(self,index,value): |
| Visual Basic .NET | | | |
| PHP | [39] | ||
| Perl | [40] | ||
| Raku | «our «type »»«multi » | «our «type »»«multi » | N/a |
| Ruby | def [](index) | def [](index) | def []=(index, value) |
| Windows PowerShell | N/a | ||
| OCaml | |||
| F# | | | |
| COBOL | N/a | ||
| Cobra | pro[index «as type»] as type | get[index «as type»] as type | set[index «as type»] as type |
| downcast | upcast | |
|---|---|---|
| ABAP Objects | N/a | |
| C++ | operatorreturntype() {instructions } | |
| C# | static explicit operatorreturntype(type operand) {instructions } | static implicit operatorreturntype(type operand) {instructions } |
| D | TopCast(T)() if (is(T ==type)) {instructions } | |
| eC | property T{ get { return «conversion code»; } } | |
| Java | N/a | |
| Objective-C | ||
| Eiffel[37] | ||
| Python | ||
| Visual Basic .NET | Shared Narrowing Operator CType(operand Astype) Asreturntype | Shared Widening Operator CType(operand Astype) Asreturntype |
| PHP | N/a | |
| Perl | ||
| Raku | multi methodtype«($self:)»is export { instructions} | |
| Ruby | N/a | |
| Windows PowerShell | ||
| OCaml | ||
| F# | ||
| COBOL | N/a | |
How to access members of an object x
| object member | class member | namespace member | |||
|---|---|---|---|---|---|
| method | field | property | |||
| ABAP Objects | x->method(«parameters»).[41] | x->field | N/a | x=>field orx=>method(«parameters[41]»). | N/a |
| C++ | x.method(parameters) or | x.field or | cls::member | ns::member | |
| Objective-C | [xmethod«:parameter «bar:parameter ...»»] | x->field | x.property (2.0 only) or | [cls method«:parameter «bar:parameter ...»»] | |
| Smalltalk | xmethod«:parameter «bar:parameter ...»» | N/a | cls method«:parameter «bar:parameter ...»» | ||
| Swift | x.method(parameters) | x.property | cls.member | ||
| APL (Dyalog) | left argument»x.method «right argument(s)» | x.field | x.property | cls.member | ns.member |
| C# | x.method(parameters) | ||||
| Java | N/a | ||||
| D | x.property | ||||
| Python | |||||
| Visual Basic .NET | |||||
| Xojo | |||||
| Windows PowerShell | [cls]::member | ||||
| F# | N/a | cls.member | |||
| eC | x.method«(parameters)» | x.field | x.property | cls::member | ns::member |
| Eiffel | x.method«(parameters)» | x.field | {cls}.member | N/a | |
| Ruby | N/a | x.property | cls.member | ||
| PHP | x->method(parameters) | x->field | x->property | cls::member | ns\member |
| Perl | x->method«(parameters)» | x->{field} | cls->method«(parameters)» | ns::member | |
| Raku | x.method«(parameters)» or | x.field or | cls.method«(parameters)» or | ns::member | |
| OCaml | x#method «parameters» | N/a | |||
| JavaScript | x.method(parameters) | x.field | x.property | cls.member | N/a |
| COBOL | INVOKE x"method" «USING parameters» «RETURNING result» or | N/a | propertyOF x | INVOKE cls"method" «USING parameters» «RETURNING result» or | N/a |
| Cobra | x.method«(parameters)» | x.field | x.property | cls.member | ns.member |
| Has member? | Handler for missing member | |||
|---|---|---|---|---|
| Method | Field | Method | Field | |
| APL (Dyalog) | 3=x.⎕NC'method' | 2=x.⎕NC'method' | N/a | |
| ABAP Objects | N/a | |||
| C++ | ||||
| Objective-C (Cocoa) | [x respondsToSelector:@selector(method)] | N/a | forwardInvocation: | N/a |
| Smalltalk | xrespondsTo: selector | N/a | doesNotUnderstand: | N/a |
| C# | (using reflection) | |||
| eC | ||||
| Java | ||||
| D | opDispatch() | |||
| Eiffel | N/a | |||
| Python | hasattr(x, "method") and callable(x.method) | hasattr(x, "field") | __getattr__() | |
| Visual Basic .NET | (using reflection) | |||
| Xojo | (using Introspection) | |||
| Windows PowerShell | (using reflection) | |||
| F# | (using reflection) | |||
| Ruby | x.respond_to?(:method) | N/a | method_missing() | N/a |
| PHP | method_exists(x, "method") | property_exists(x, "field") | __call() | __get() / __set() |
| Perl | x->can("method") | existsx->{field} | AUTOLOAD | |
| Raku | x.can("method") | x.field.defined | AUTOLOAD | |
| OCaml | N/a | |||
| JavaScript | typeofx.method === "function" | fieldin x | ||
| COBOL | N/a | |||
| current object | current object'sparent object | null reference | Current Context of Execution | |
|---|---|---|---|---|
| Smalltalk | self | super | nil | thisContext |
| ABAP Objects | me | super | initial | |
| APL (Dyalog) | ⎕THIS | ⎕BASE | ⎕NULL | |
| C++ | *this | [42] | NULL,nullptr | |
| C# | this | base[43] | null | |
| Java | super[43] | |||
| D | ||||
| JavaScript | super[43] (ECMAScript 6) | null,undefined[44] | ||
| eC | this | null | ||
| Objective-C | self | super[43] | nil | |
| Swift | self | super[43] | nil[45] | |
| Python | self[46] | super(current_class_name, self)[7]super() (3.x only) | None | |
| Visual Basic .NET | Me | MyBase | Nothing | |
| Xojo | Me / Self | Parent | Nil | |
| Eiffel | Current | Precursor «{superclass}» «(args)»[43][47] | Void | |
| PHP | $this | parent[43] | null | |
| Perl | $self[46] | $self->SUPER[43] | undef | |
| Raku | self | SUPER | Nil | |
| Ruby | self | super«(args)»[48] | nil | binding |
| Windows PowerShell | $this | $NULL | ||
| OCaml | self[49] | super[50] | N/a[51] | |
| F# | this | base[43] | null | |
| COBOL | SELF | SUPER | NULL | |
| Cobra | this | base | nil |
| String representation | Object copy | Value equality | Object comparison | Hash code | Object ID | ||
|---|---|---|---|---|---|---|---|
| Human-readable | Source-compatible | ||||||
| ABAP Objects | N/a | ||||||
| APL (Dyalog) | ⍕x | ⎕SRC x | ⎕NS x | x= y | N/a | ||
| C++ | x== y[52] | pointer to object can be converted into an integer ID | |||||
| C# | x.ToString() | x.Clone() | x.Equals(y) | x.CompareTo(y) | x.GetHashCode() | System | |
| Java | x.toString() | x.clone()[53] | x.equals(y) | x.compareTo(y)[54] | x.hashCode() | System | |
| JavaScript | x.toString() | ||||||
| D | x.toString() or | x.stringof | x== y or | x.opCmp(y) | x.toHash() | ||
| eC | x.OnGetString(tempString, null, null) or | y.OnCopy(x) | x.OnCompare(y) | object handle can be converted into an integer ID | |||
| Objective-C (Cocoa) | x.description | x.debugDescription | [x copy][55] | [x isEqual:y] | [x compare:y][56] | x.hash | pointer to object can be converted into an integer ID |
| Swift | x.description[57] | x.debugDescription[58] | x== y[59] | x< y[60] | x.hashValue[61] | reflect(x) | |
| Smalltalk | xdisplayString | xprintString | xcopy | x= y | xhash | xidentityHash | |
| Python | str(x)[62] | repr(x)[63] | copy.copy(x)[64] | x== y[65] | cmp(x,y)[66] | hash(x)[67] | id(x) |
| Visual Basic .NET | x.ToString() | x.Clone() | x.Equals(y) | x.CompareTo(y) | x.GetHashCode() | ||
| Eiffel | x.out | x.twin | x.is_equal(y) | When x isCOMPARABLE, one can simply dox< y | When x isHASHABLE, one can usex.hash_code | When x isIDENTIFIED, one can usex.object_id | |
| PHP | $x->__toString() | clone x[68] | x== y | | spl_object_hash(x) | ||
| Perl | "$x"[69] | Data::Dumper[70] | Storable[71] | Scalar[72] | |||
| Raku | ~x[69] | x.perl | x.clone | xeqv y | xcmp y | x.WHICH | |
| Ruby | x.to_s | x.inspect | x.dup or | x== y or | x<=> y | x.hash | x.object_id |
| Windows PowerShell | x.ToString() | x.Clone() | x.Equals(y) | x.CompareTo(y) | x.GetHashCode() | ||
| OCaml | Oo.copy x | x= y | Hashtbl | Oo.id x | |||
| F# | string x or x | sprintf "%A" x | x.Clone() | x= y or x | compare x y or x | hash x or x | |
| COBOL | N/a | ||||||
| Get object type | Is instance of (includes subtypes) | Upcasting | Downcasting | ||
|---|---|---|---|---|---|
| Runtime check | No check | ||||
| ABAP Objects | N/a[73] | = | ?= | ||
| C++ | typeid(x) | dynamic_cast<type *>(&x) !=nullptr | N/a[74] | dynamic_cast<type*>(ptr) | (type*) ptr or |
| C# | x.GetType() | xis type | (type) x or xas type | ||
| D | typeid(x) | cast(type) x | |||
| Delphi | xis type | xas type | |||
| eC | x._class | eClass_IsDerived(x._class, type) | (type) x | ||
| Java | x.getClass() | xinstanceof class | (type) x | ||
| Objective-C (Cocoa) | [x class][75] | [x isKindOfClass:[class class]] | (type*) x | ||
| Swift | x.dynamicType | xis type | xas! typexas? type | ||
| JavaScript | x.constructor(If not rewritten.) | xinstanceof class | N/a[76] | ||
| Visual Basic .NET | x.GetType() | TypeOf xIs type | N/a[74] | CType(x,type) orTryCast(x,type) | |
| Xojo | Introspection.GetType(x) | xIsA type | N/a | CType(x,type) | N/a |
| Eiffel | x.generating_type | attached {TYPE} x | attached {TYPE} xas down_x | ||
| Python | type(x) | isinstance(x,type) | N/a[76] | ||
| PHP | get_class(x) | xinstanceof class | |||
| Perl | ref(x) | x->isa("class") | |||
| Raku | x.WHAT | x.isa(class) | N/a[74] | type(x) or | |
| Ruby | x.class | x.instance_of?(type) or | N/a[76] | ||
| Smalltalk | xclass | xisKindOf: class | |||
| Windows PowerShell | x.GetType() | x-is [type] | N/a[74] | [type]x or x-as [type] | |
| OCaml | N/a[77] | (x:> type) | N/a | ||
| F# | x.GetType() | x:? type | (x:?> type) | ||
| COBOL | N/a | xAS type[74] | N/a | ||
| Import namespace | Import item | ||
|---|---|---|---|
| qualified | unqualified | ||
| ABAP Objects | |||
| C++ | using namespace ns; | using ns::item; | |
| C# | using ns; | using item= ns.item; | |
| D | import ns; | import ns: item; | |
| Java | import ns.*; | import ns.item; | |
| Objective-C | |||
| Visual Basic .NET | Imports ns | ||
| Eiffel | |||
| Python | import ns | from nsimport * | from nsimport item |
| PHP | use ns; | use ns\item; | |
| Perl | use ns; | use ns qw(item); | |
| Raku | |||
| Ruby | |||
| Windows PowerShell | |||
| OCaml | open ns | ||
| F# | |||
| COBOL | N/a | ||
| Precondition | Postcondition | Check | Invariant | Loop | |
|---|---|---|---|---|---|
| ABAP Objects | N/a | ||||
| C++ | |||||
| C# | Spec#: | Spec#: | |||
| Java | N/a | ||||
| Objective-C | |||||
| Visual Basic .NET | |||||
| D | f | f | assert(expression) | invariant() {expression } | |
| Eiffel | f | f | f | class X | from instructions |
| Python | N/a | ||||
| PHP | |||||
| Perl | |||||
| Raku | PRE { condition} | POST { condition} | |||
| Ruby | N/a | ||||
| Windows PowerShell | |||||
| OCaml | |||||
| F# | |||||
| COBOL | |||||
NSObject for Cocoa and GNUstep, orObject otherwise.@interface portion is placed into aheader file, and the@interface portion is placed into a separate source code file."member_name(parameters)""class_name(parameters)".classaddInstVarName:field.classremoveInstVarName:field.
defbar():doc="The bar property."deffget(self):returnself._bardeffset(self,value):self._bar=valuereturnlocals()bar=property(**bar())
@{} (array dereference) or subclass one ofTie::Array orTie::StdArray to hook array operationsx->method(«exporting parameter = argument» «importing parameter = argument» «changing parameter = argument» «returning value(parameter)»parameter = argument can be repeated if there are several parametersBaseClassName::member syntax can be used to access an overridden member in the specified base class. Microsoft Visual C++ provides a non-standard keyword "__super" for this purpose; but this is unsupported in other compilers.[1]option type, which values areNone andSome x, which could be used to represent "null reference" and "non-null reference to an object" as in other languages.== operatorclone() method inherited fromObject is protected, unless the class overrides the method and makes it public. If using theclone() inherited fromObject, the class must implement theCloneable interface to allow cloning.Comparable for this method to be standardized.copyWithZone: methodcompare: is the conventional name for the comparison method in Foundation classes. However, no formal protocol existsPrintable protocolDebugPrintable protocolEquatable protocolComparable protocolhashValue protocol__str__() method__repr__() method__copy__() method__eq__() method__cmp__() method__hash__() method. Not all types are hashable (mutable types are usually not hashable)__clone() methodx is a class object,[x class] returns onlyx. The runtime methodobject_getClass(x) will return the class ofx for all objects.