# Comparison of programming languages (object-oriented programming)

This comparison of programming languages compares how object-oriented programming languages such as C++, Java, Smalltalk, Object Pascal, Perl, Python, and others manipulate data structures.

## Object construction and destruction

| | construction | destruction |
| ABAP Objects | data variable type ref to class . create object variable «exporting parameter = argument». | |
| APL (Dyalog) | variable←⎕NEW class «parameters» | ⎕EX 'variable' |
| C++ | class variable«(parameters)»; or class *variable = new class«(parameters)»; | delete pointer; |
| C# | class variable = new class(parameters); | variable.Dispose; |
| Java | class variable = new class(parameters); | |
| D | class variable = new class(parameters); | destroy(variable); |
| eC | class «instance handle» { «properties/data members assignments, instance method overrides» } | delete instance handle; |
| Objective-C (Cocoa) | class *variable = [[class alloc ] init]; or class *variable = [[class alloc ] initWithFoo:parameter «bar:parameter ...»]; | [variable release]; |
| Swift | let variable = class(parameters) | |
| Python | variable = class(parameters) | del variable (Normally not needed) |
| Visual Basic .NET | Dim variable As New class(parameters) | variable.Dispose |
| Xojo | Dim variable As New class(parameters) | variable = Nil |
| Eiffel | create variable or create «{TYPE}» variable.make_foo «(parameters)» or variable := create {TYPE} or variable := create {TYPE}.make_foo «(parameters)» | |
| PHP | $variable = new class«(parameters)»; | unset($variable); |
| Perl 5 | «my »$variable = class->new«(parameters)»; | undef($variable); |
| Raku | «my »$variable = class.new«(parameters)»; | $variable.undefine; |
| Ruby | variable = class.new«(parameters)» | |
| Windows PowerShell | $variable = New-Object «-TypeName» class ««-ArgumentList» parameters» | Remove-Variable «-Name» variable |
| OCaml | let variable = new class «parameters» or let variable = object members end | |
| 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: Point x: 10 y: 20. Array with: -1 with: 3 with: 2. | |
| JavaScript | var variable = new class«(parameters)» or var variable = { «key1: value1«, key2: value2 ...»»} | |
| Object Pascal (Delphi) | ClassVar := ClassType.ConstructorName(parameters); | ClassVar.Free; |
| Scala | val obj = new Object // no parameters val obj = new Object(arg0, arg1, arg2...) val obj = Object(arg0, arg1, arg2...) // case class val obj = new Object(arg0, arg1, param1 = value1, ...) // named parameters | |
| COBOL | INVOKE class "NEW" RETURNING variable or MOVE 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] ..]))) | |

## Class declaration

| | class | protocol | namespace |
| ABAP Objects | class name definition «inheriting from parentclass». «interfaces: interfaces.» method_and_field_declarations endclass. class name implementation. method_implementations endclass. | interface name. members endinterface. | — |
| APL (Dyalog) | :Class name «:parentclass» «,interfaces» members :EndClass | :Interface name members :EndInterface | :Namespace name members :EndNamespace |
| C++ | class name« : public parentclasses» { members }; | | namespace name { members } |
| C# | class name« : «parentclass»«, interfaces»» { members } | interface name« : parentinterfaces» { members } | namespace name { members } |
| D | class name« : «parentclass»«, interfaces»» { members } | interface name« : parentinterfaces» { members } | module name; members |
| eC | class name« : base class» { «default member values assignments» «members» } | | namespace name; |
| Java | class name« extends parentclass»« implements interfaces» { members } | interface name« extends parentinterfaces» { members } | package name; members |
| PHP | class name« extends parentclass»« implements interfaces» { members } | interface name« extends parentinterfaces» { members } | namespace name; members |
| Objective-C | @interface name« : parentclass»«< protocols >» { instance_fields } method_and_property_declarations @end @implementation name method_implementations @end | @protocol name«< parentprotocols >» members @end | |
| Swift | class name« : «parentclass»«, protocols»» { members } | protocol name« : parentprotocols» { members } | |
| Python | class name«(parentclasses)»: Tab ↹ members | | __all__ = [ member1,member2,... ] |
| Visual Basic .NET | Class name« Inherits parentclass»« Implements interfaces» members End Class | Interface name« Inherits parentinterfaces» members End Interface | Namespace name members End Namespace |
| Xojo | Class name« Inherits parentclass»« Implements interfaces» members End Class | Interface name« Inherits parentinterfaces» members End Interface | Module name members End Module |
| Eiffel | class name« inherit parentclasses» members end | — | — |
| Perl | package name; «@ISA = qw(parentclasses);» members 1; | | package name; members |
| Raku | class name «is parentclass «is parentclass ...»» «does role «does role ...»» { members } | role name «does role «does role ...»» { members } | module name { members } |
| Ruby | class name« < parentclass» members end | | module name members end |
| Windows PowerShell | — | — | — |
| OCaml | class name «parameters» = object «(self)» «inherit parentclass «parameters» «inherit parentclass «parameters» ...»» members end | | module name members |
| F# | type name«(parameters)» «as this» = class «inherit parentclass«(parameters)» «as base»» members «interface interface with implementation «interface interface with implementation ...»» end | type name = interface members end | namespace name members |
| Smalltalk | | | |
| JavaScript (ES6) | class name «extends parentclass» { members } | | |
| Object Pascal (Delphi) | ClassName = Class «(ClassParent, Interfaces)» private // Private members(include Methods and Fields) public // Public members protected // Protected members published // Published members end; | | package name; members |
| Scala | class ConcreteClass(constructor params) extends ParentClass with Trait1 with Trait2 with Trait2 { // members } | trait TraitName extends OtherTrait1 with OtherTrait2 with OtherTrait3 { // members } | package name |
| COBOL | CLASS-ID. name« INHERITS« FROM» parentclasses». FACTORY« IMPLEMENTS interfaces». class-members END FACTORY. OBJECT« IMPLEMENTS interfaces». instance-members END OBJECT. END CLASS name. | INTERFACE-ID. name« INHERITS« FROM» interfaces». members END INTERFACE name. | — |
| Cobra | class name «inherits parentclass» «implements interfaces» Tab ↹ members | interface name «inherits parentinterfaces» Tab ↹ members | namespace name Tab ↹ members |
| ISLISP | (defclass name (base-class) ((x :initform 0 :accessor get-x :initarg x)) (:abstractp nil)) | | |

## Class members
### Constructors and destructors

| | constructor | destructor | finalizer |
| ABAP Objects | methods constructor «importing parameter = argument» method constructor. instructions endmethod. | — | — |
| APL (Dyalog) | ∇ name :Implements Constructor «:Base «expr»» instructions ∇ | | ∇ name :Implements Destructor instructions ∇ |
| C++ | class(«parameters») «: initializers» { 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 | | | |
| Objective-C (Cocoa) | - (id)init { instructions... return self; } or - (id)initWithFoo:parameter «bar:parameter ...» { instructions... return self; } | - (void)dealloc { instructions } | - (void)finalize { instructions } |
| Swift | init(«parameters») { instructions } | deinit { instructions } | |
| Python | def __init__(self«, parameters»): Tab ↹ instructions | | def __del__(self): Tab ↹ instructions |
| Visual Basic .NET | Sub New(«parameters») instructions End Sub | Sub Dispose instructions End Sub | Overrides Sub Finalize instructions End Sub |
| Xojo | Sub Constructor(«parameters») instructions End Sub | Sub Destructor instructions End Sub | |
| PHP | function __construct(«parameters») { instructions } | function __destruct { instructions } | |
| Perl | sub new { my ($class«, parameters») = @_; my $self =; instructions ... bless($self, $class); return $self; } | sub DESTROY { my ($self) = @_; instructions } | |
| Raku | submethod BUILD { instructions } or «multi » method new(««$self: »parameters») { self.bless(*, field1 => value1, ...); ... instructions } | submethod DESTROY { instructions } | |
| Ruby | def initialize«(parameters)» instructions end | — | — |
| Windows PowerShell | — | — | — |
| OCaml | initializer instructions | — | — |
| F# | do instructions or new(parameters) = expression | member this.Dispose = instructions | override this.Finalize = instructions |
| JavaScript | function name(«parameters») { instructions } | — | — |
| JavaScript (ES6) | constructor(«parameters») { instructions } |
| COBOL | — | — | — |
| Cobra | cue init(parameters) Tab ↹ base.init Tab ↹ instructions | def dispose Tab ↹ instructions | |
| ISLISP | (defmethod initialize-object ((instance <class-name>) initvalues) | |

### Fields

| | public | private | protected | friend |
| ABAP Objects | public section. data field type type. | private section. data field type type. | protected section. data field type type. | |
| APL (Dyalog) | :Field Public field «← value» | :Field «Private» field «← value» | | |
| C++ | public: type field; | private: type field; | protected: type field; | |
| C# | public type field «= value»; | private type field «= value»; | protected type field «= value»; | internal type field «= value»; |
| D | public type field «= value»; | private type field «= value»; | | package type field «= value»; |
| Java | public type field «= value»; | private type field «= value»; | protected type field «= value»; | type field «= value»; |
| eC | public type field; | private type field; |
| Eiffel | feature field: TYPE | feature {NONE} field: TYPE | feature {current_class} field: TYPE | feature {FRIEND} field: TYPE |
| Objective-C | @public type field; | @private type field; | @protected type field; | @package type field; |
| Swift | — | — | — | — |
| Smalltalk | — | — | | — |
| Python | self.field = value | — | — | — |
| Visual Basic .NET | Public field As type «= value» | Private field As type «= value» | Protected field As type «= value» | Friend field As type «= value» |
| Xojo | Public field As type «= value» | Private field As type «= value» | Protected field As type «= value» | — |
| PHP | public $field «= value»; | private $field «= value»; | protected $field «= value»; | |
| Perl | $self->{field} = value; | — | — | — |
| Raku | has« type »$.field« is rw» | has« type »$!field | — | — |
| Ruby | — | — | @field = value | |
| Windows PowerShell | Add-Member «-MemberType »NoteProperty «-Name »Bar «-Value »value -InputObject variable | — | — | — |
| OCaml | — | — | val «mutable» field = value | — |
| F# | — | let «mutable» field = value | — | — |
| JavaScript | this.field = value this["field"] = value | | | |
| COBOL | — | level-number field clauses. | — | — |
| 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) | | | |

### Methods

| | basic/void method | value-returning method |
| ABAP Objects | methods name «importing parameter = argument» «exporting parameter = argument» «changing parameter = argument» «returning value(parameter)» method name. instructions endmethod. | |
| APL (Dyalog) | ∇ «left argument» name «right arguments» instructions ∇ | ∇ result ← «left argument» name «right arguments» instructions ∇ |
| C++ type foo(«parameters»); The implementation of methods is usually provided in a separate source file, with the following syntax type class::foo(«parameters») { instructions } | void foo(«parameters») { instructions } | type foo(«parameters») { instructions ... return value; } |
| C# | void foo(«parameters») { instructions } | type foo(«parameters») { instructions ... return value; } |
| D | void foo(«parameters») { instructions } | type foo(«parameters») { instructions ... return value; } |
| Java | void foo(«parameters») { instructions } | type foo(«parameters») { instructions ... return value; } |
| eC | void ««type of 'this'»::»foo(«parameters») { instructions } | type ««type of this»::»foo(«parameters») { instructions ... return value; } |
| Eiffel | foo ( «parameters» ) do instructions end | foo ( «parameters» ): TYPE do instructions... Result := value end |
| Objective-C | - (void)foo«:parameter «bar:parameter ...»» { instructions } | - (type)foo«:parameter «bar:parameter ...»» { instructions... return value; } |
| Swift | func foo(«parameters») { instructions } | func foo(«parameters») -> type { instructions... return value } |
| Python | def foo(self«, parameters»): Tab ↹ instructions | def foo(self«, parameters»): Tab ↹ instructions Tab ↹ return value |
| Visual Basic .NET | Sub Foo(«parameters») instructions End Sub | Function Foo(«parameters») As type instructions ... Return value End Function |
| Xojo | Sub Foo(«parameters») instructions End Sub | Function Foo(«parameters») As type instructions ... Return value End Function |
| PHP | function foo(«parameters»)«: void» { instructions } | function foo(«parameters»)«: type» { instructions ... return value; } |
| Perl | sub foo { my ($self«, parameters») = @_; instructions } | sub foo { my ($self«, parameters») = @_; instructions ... return value; } |
| Raku | «has »«multi »method foo(««$self: »parameters») { instructions } | «has «type »»«multi »method foo(««$self: »parameters») { instructions ... return value; } |
| Ruby | def foo«(parameters)» instructions end | def foo«(parameters)» instructions expression resulting in return value end or def foo«(parameters)» instructions return value end |
| Windows PowerShell | Add-Member «-MemberType» ScriptMethod «-Name» foo «-Value» { «param(parameters)» instructions } -InputObject variable | Add-Member «-MemberType» ScriptMethod «-Name» foo «-Value» { «param(parameters)» instructions ... return value } -InputObject variable |
| OCaml | — | method foo «parameters» = expression |
| F# | — | member this.foo(«parameters») = expression |
| JavaScript | this.method = function(«parameters») {instructions} name«.prototype.method = function(«parameters») {instructions} | this.method = function(«parameters») {instructions... return value;} name«.prototype.method = function(«parameters») {instructions... return value;} |
| Javascript (ES6) | foo(«parameters») {instructions} | foo(«parameters») {instructions... return value;} |
| COBOL | METHOD-ID. foo. «DATA DIVISION. LINKAGE SECTION. parameter declarations» PROCEDURE DIVISION« USING parameters». instructions END METHOD foo. | METHOD-ID. foo. DATA DIVISION. LINKAGE SECTION. «parameter declarations» result-var declaration PROCEDURE DIVISION« USING parameters» RETURNING result-var. instructions END METHOD foo. |
| Cobra | def foo(parameters) Tab ↹ instructions | def foo(parameters) as type Tab ↹ instructions Tab ↹ return value |
| ISLISP | (defgeneric method (arg1 arg2)) (defmethod method ((arg1 <class1> arg2 <class2>) ...) | |

### Properties

How to declare a property named "Bar"

#### Manually implemented

| | read-write | read-only | write-only |
| ABAP Objects | — | — | — |
| APL (Dyalog) | :Property Bar ∇ result ← Get instructions ∇ ∇ Set arguments instructions ∇ :EndProperty Bar | :Property Bar ∇ result ← Get instructions ∇ :EndProperty Bar | :Property Bar ∇ Set arguments instructions ∇ :EndProperty Bar |
| C++ | — | — | — |
| C# | type Bar { get { instructions ... return value; } set { instructions } } | type Bar { get { instructions ... return value; } } | type Bar { set { instructions } } |
| D | @property type bar { instructions ... return value; } @property type bar(type value) { instructions ... return value; } | @property type bar { instructions ... return value; } | @property type bar(type value) { instructions ... return value; } |
| eC | property type Bar { get { instructions ... return value; } set { instructions } } | property type Bar { get { instructions ... return value; } } | property type Bar { set { instructions } } |
| Java | — | — | — |
| Objective-C 2.0 (Cocoa) | @property (readwrite) type bar; and then inside @implementation - (type)bar { instructions } - (void)setBar:(type)value { instructions } | @property (readonly) type bar; and then inside @implementation - (type)bar { instructions } | — |
| Swift | var bar : type { get { instructions } set«(newBar)» { instructions } } | var bar : type { instructions } | — |
| Eiffel | feature -- Access x: TYPE assign set_x feature -- Settings set_x (a_x: like x) do instructions ensure x_set: verification end | | |
| Python | def setBar(self, value): Tab ↹ instructions def getBar(self): Tab ↹ instructions Tab ↹ return value bar = property(getBar, setBar) | def getBar(self): Tab ↹ instructions Tab ↹ return value bar = property(getBar) | def setBar(self, value): Tab ↹ instructions bar = property(fset = setBar) |
| Visual Basic .NET | Property Bar As type Get instructions Return value End Get Set (ByVal Value As type) instructions End Set End Property | ReadOnly Property Bar As type Get instructions Return value End Get End Property | WriteOnly Property Bar As type Set (ByVal Value As type) instructions End Set End Property |
| Xojo | ComputedProperty Bar As type Get instructions Return value End Get Set (ByVal Value As type) instructions End Set End ComputedProperty | ComputedProperty Bar As type Get instructions Return value End Get End ComputedProperty | ComputedProperty Bar As type Set (value As type) instructions End Set End ComputedProperty |
| PHP | function __get($property) { switch ($property) { case 'Bar' : instructions ... return value; } } function __set($property, $value) { switch ($property) { case 'Bar' : instructions } } | function __get($property) { switch ($property) { case 'Bar' : instructions ... return value; } } | function __set($property, $value) { switch ($property) { case 'Bar' : instructions } } |
| Perl | sub Bar { my $self = shift; if (my $Bar = shift) { # setter $self->{Bar} = $Bar; return $self; } else { # getter return $self->{Bar}; } } | sub Bar { my $self = shift; if (my $Bar = shift) { # read-only die "Bar is read-only\n"; } else { # getter return $self->{Bar}; } } | sub Bar { my $self = shift; if (my $Bar = shift) { # setter $self->{Bar} = $Bar; return $self; } else { # write-only die "Bar is write-only\n"; } } |
| Raku | — | — | — |
| Ruby | def bar instructions expression resulting in return value end def bar=(value) instructions end | def bar instructions expression resulting in return value end | def bar=(value) instructions end |
| Windows PowerShell | Add-Member «-MemberType »ScriptProperty «-Name »Bar «-Value »{ instructions ... return value } «-SecondValue »{ instructions } -InputObject variable | Add-Member «-MemberType »ScriptProperty «-Name »Bar «-Value »{ instructions ... return value} -InputObject variable | Add-Member «-MemberType »ScriptProperty «-Name »Bar -SecondValue { instructions } -InputObject variable |
| OCaml | — | — | — |
| F# | member this.Bar with get = expression and set(value) = expression | member this.Bar = expression | member this.Bar with set(value) = expression |
| JavaScript (ES6) | get bar(«parameters») { instructions ... return value}set bar(«parameters») { instructions } | get bar(«parameters») { instructions ... return value} | set bar(«parameters») { instructions } |
| COBOL | METHOD-ID. GET PROPERTY bar. DATA DIVISION. LINKAGE SECTION. return-var declaration PROCEDURE DIVISION RETURNING return-var. instructions END METHOD. METHOD-ID. SET PROPERTY bar. DATA DIVISION. LINKAGE SECTION. value-var declaration PROCEDURE DIVISION USING value-var. instructions END METHOD. | METHOD-ID. GET PROPERTY bar. DATA DIVISION. LINKAGE SECTION. return-var declaration PROCEDURE DIVISION RETURNING return-var. instructions END METHOD. | METHOD-ID. SET PROPERTY bar. DATA DIVISION. LINKAGE SECTION. value-var declaration PROCEDURE DIVISION USING value-var. instructions END METHOD. |
| Cobra | pro bar «as type» Tab ↹ get Tab ↹Tab ↹ instructions Tab ↹Tab ↹ return value Tab ↹ set Tab ↹Tab ↹ instructions | get bar «as type» Tab ↹ instructions Tab ↹ return value | set bar «as type» Tab ↹ instructions |
| ISLISP | — | — | — |

#### Automatically implemented

| | read-write | read-only | write-only |
| ABAP Objects | — | — | — |
| C++ | — | — | — |
| C# | type Bar { get; set; } | type Bar { get; private set; } | type Bar { private get; set; } |
| D | — | — | — |
| Java | — | — | — |
| Objective-C 2.0 (Cocoa) | @property (readwrite) type bar; and then inside @implementation @synthesize bar; | @property (readonly) type bar; and then inside @implementation @synthesize bar; | — |
| Swift | var bar : type | let bar : type | — |
| Eiffel | | | |
| Python | @property def bar(self): Tab ↹instructions @bar.setter def bar(self, value): Tab ↹instructions | @property def bar(self): Tab ↹instructions | bar = property @bar.setter def bar(self, value): Tab ↹instructions |
| Visual Basic .NET | Property Bar As type« = initial_value» (VB 10) | | |
| PHP | | | |
| Perl | use base qw(Class::Accessor); __PACKAGE__->mk_accessors('Bar'); | use base qw(Class::Accessor); __PACKAGE__->mk_ro_accessors('Bar'); | use base qw(Class::Accessor); __PACKAGE__->mk_wo_accessors('Bar'); |
| Raku | — | — | — |
| Ruby | attr_accessor :bar | attr_reader :bar | attr_writer :bar |
| Windows PowerShell | | | |
| OCaml | — | — | — |
| F# | member val Bar = value with get, set | | |
| COBOL | level-number bar clauses PROPERTY. | level-number bar clauses PROPERTY «WITH» NO SET. | level-number bar clauses PROPERTY «WITH» NO GET. |
| Cobra | pro bar from var «as type» | get bar from var «as type» | set bar from var «as type» |

### Overloaded operators
#### Standard operators

| | unary | binary | function call |
| ABAP Objects | — | — | — |
| C++ | type operator symbol { instructions } | type operator symbol (type operand2) { instructions } | type operator («parameters») { instructions } |
| C# | static type operator symbol(type operand) { instructions } | static type operator symbol(type operand1, type operand2) { instructions } | — |
| D | type opUnary(string s) if (s == "symbol") { instructions } | type opBinary(string s)(type operand2) if (s == "symbol") { instructions } type opBinaryRight(string s)(type operand1) if (s == "symbol") switch (s) { instructions } | type opCall(«parameters») { instructions } |
| Java | — | — | — |
| Objective-C | — | — | — |
| Swift | func symbol(operand1 : type) -> returntype { instructions } (outside class) | func symbol(operand1 : type1, operand2 : type2) -> returntype { instructions } (outside class) | |
| Eiffel | op_name alias "symbol": TYPE do instructions end | op_name alias "symbol" (operand: TYPE1): TYPE2 do instructions end | |
| Python | def __opname__(self): Tab ↹ instructions Tab ↹ return value | def __opname__(self, operand2): Tab ↹ instructions Tab ↹ return value | def __call__(self«, parameters»): Tab ↹ instructions Tab ↹ return value |
| Visual Basic .NET | Shared Operator symbol(operand As type) As type instructions End Operator | Shared Operator symbol(operand1 As type, operand2 As type) As type instructions End Operator | — |
| Xojo | Function Operator_name(operand As type) As type instructions End Function | — | — |
| PHP | | | function __invoke(«parameters») { instructions } (PHP 5.3+) |
| Perl | use overload "symbol" => sub { my ($self) = @_; instructions }; | use overload "symbol" => sub { my ($self, $operand2, $operands_reversed) = @_; instructions }; | |
| Raku | «our «type »»«multi »method prefix:<symbol> («$operand: ») { instructions ... return value; } or «our «type »»«multi »method postfix:<symbol> («$operand: ») { instructions ... return value; } or «our «type »»«multi »method circumfix:<symbol1 symbol2> («$operand: ») { instructions ... return value; } | «our «type »»«multi »method infix:<symbol> («$operand1: » type operand2) { instructions ... return value; } | «our «type »»«multi »method postcircumfix:<( )> («$self: » «parameters») { instructions } |
| Ruby | def symbol instructions expression resulting in return value end | def symbol(operand2) instructions expression resulting in return value end | — |
| Windows PowerShell | — | — | — |
| OCaml | — | — | — |
| F# | static member (symbol) operand = expression | static member (symbol) (operand1, operand2) = expression | — |
| COBOL | — | — | — |
| ISLISP | — | — | — |

#### Indexers

| | read-write | read-only | write-only |
| ABAP Objects | — | — | — |
| APL (Dyalog) | :Property Numbered Default name ∇ result ← Get instructions ∇ ∇ Set arguments instructions ∇ :EndProperty Bar | :Property Numbered Default Bar ∇ result ← Get instructions ∇ :EndProperty Bar | :Property Numbered Default Bar ∇ Set arguments instructions ∇ :EndProperty Bar |
| C++ | type& operator(type index) { instructions } | type operator(type index) { instructions } | |
| C# | type this[type index] { get{ instructions } set{ instructions } } | type this[type index] { get{ instructions } } | type this[type index] { set{ instructions } } |
| D | type opIndex(type index) { instructions } type opIndexAssign(type value, type index) { instructions } | type opIndex(type index) { instructions } | type opIndexAssign(type value, type index) { instructions } |
| Java | — | — | — |
| Objective-C (recent Clang compiler) | — | - (id)objectAtIndexedSubscript:(NSUInteger)index { instructions return value; } or - (id)objectForKeyedSubscript:(id)index { instructions return value; } | - (void)setObject:(id)value atIndexedSubscript:(NSUInteger)index { instructions } or - (void)setObject:(id)value forKeyedSubscript:(id)index { instructions } |
| Swift | subscript (index : type) -> returntype { get { instructions } set«(newIndex)» { instructions } } | subscript (index : type) -> returntype { instructions } | |
| Eiffel | bracket_name alias "" (index: TYPE): TYPE assign set_item do instructions end set_item (value: TYPE; index: TYPE): do instructions end | bracket_name alias "" (index: TYPE): TYPE do instructions end | |
| Python | def __getitem__(self, index): Tab ↹ instructions Tab ↹ return value def __setitem__(self, index, value): Tab ↹ instructions | def __getitem__(self, index): Tab ↹ instructions Tab ↹ return value | def __setitem__(self, index, value): Tab ↹ instructions |
| Visual Basic .NET | Default Property Item(Index As type) As type Get instructions End Get Set(ByVal Value As type) instructions End Set End Property | Default ReadOnly Property Item(Index As type) As type Get instructions End Get End Property | Default WriteOnly Property Item(Index As type) As type Set(ByVal Value As type) instructions End Set End Property |
| PHP | | | |
| Perl | | | |
| Raku | «our «type »»«multi »method postcircumfix:<[ ]> is rw («$self: » type $index) { instructions ... return value; } or «our «type »»«multi »method postcircumfix:<{ }> is rw («$self: » type $key) { instructions ... return value; } | «our «type »»«multi »method postcircumfix:<[ ]>(«$self: » type $index) { instructions ... return value; } or «our «type »»«multi »method postcircumfix:<{ }> («$self: » type $key) { instructions ... return value; } | — |
| Ruby | def(index) instructions expression resulting in return value end def=(index, value) instructions end | def(index) instructions expression resulting in return value end | def=(index, value) instructions end |
| Windows PowerShell | — | — | — |
| OCaml | — | — | — |
| F# | member this.Item with get(index) = expression and set index value = expression | member this.Item with get(index) = expression | member this.Item with set index value = expression |
| COBOL | — | — | — |
| Cobra | pro[index «as type»] as type Tab ↹ get Tab ↹Tab ↹ instructions Tab ↹Tab ↹ return value Tab ↹ set Tab ↹Tab ↹ instructions | get[index «as type»] as type Tab ↹ instructions Tab ↹ return value | set[index «as type»] as type Tab ↹ instructions |

#### Type casts

| | downcast | upcast |
| ABAP Objects | — | — |
| C++ | | operator returntype { instructions } |
| C# | static explicit operator returntype(type operand) { instructions } | static implicit operator returntype(type operand) { instructions } |
| D | | T opCast(T) if (is(T == type)) { instructions } |
| eC | | property T { get { return «conversion code»; } } |
| Java | — | — |
| Objective-C | — | — |
| Eiffel | — | — |
| Python | — | — |
| Visual Basic .NET | Shared Narrowing Operator CType(operand As type) As returntype instructions End Operator | Shared Widening Operator CType(operand As type) As returntype instructions End Operator |
| PHP | — | — |
| Perl | — | — |
| Raku | | multi method type«($self:)» is export { instructions } |
| Ruby | — | — |
| Windows PowerShell | — | — |
| OCaml | — | — |
| F# | | |
| COBOL | — | — |

## Member access

How to access members of an object x
| | object member | object member | object member | class member | namespace member |
| | method | field | property | class member | namespace member |
| ABAP Objects | x->method(«parameters»). | x->field | — | x=>field or x=>method(«parameters»). | — |
| C++ | x.method(parameters) or ptr->method(parameters) | x.field or ptr->field | | cls::member | ns::member |
| Objective-C | [x method«:parameter «bar:parameter ...»»] | x->field | x.property (2.0 only) or [x property] | [cls method«:parameter «bar:parameter ...»»] | |
| Smalltalk | x method«:parameter «bar:parameter ...»» | — | | 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) | x.field | | cls.member | ns.member |
| Java | x.method(parameters) | x.field | — | cls.member | ns.member |
| D | x.method(parameters) | x.field | x.property | cls.member | ns.member |
| Python | x.method(parameters) | x.field | x.property | cls.member | ns.member |
| Visual Basic .NET | x.method(parameters) | x.field | x.property | cls.member | ns.member |
| Xojo | x.method(parameters) | x.field | x.property | cls.member | ns.member |
| Windows PowerShell | x.method(parameters) | x.field | x.property | [cls]::member | ns.member |
| F# | x.method(parameters) | — | x.property | cls.member | ns.member |
| eC | x.method«(parameters)» | x.field | x.property | cls::member | ns::member |
| Eiffel | x.method«(parameters)» | x.field | | {cls}.member | — |
| Ruby | x.method«(parameters)» | — | 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!method«(parameters)» | x.field or x!field | | cls.method«(parameters)» or cls!method«(parameters)» | ns::member |
| OCaml | x#method «parameters» | — | — | | |
| JavaScript | x.method(parameters) x["method"](parameters) | x.field x["field"] | x.property x["property"] | cls.member cls["member"] | — |
| COBOL | INVOKE x "method" «USING parameters» «RETURNING result» or x::"method"«(«parameters»)» | — | property OF x | INVOKE cls "method" «USING parameters» «RETURNING result» or cls::"method"«(«parameters»)» or property OF cls | — |
| Cobra | x.method«(parameters)» | x.field | x.property | cls.member | ns.member |

## Member availability

| | Has member? | Has member? | Handler for missing member | Handler for missing member |
| | Method | Field | Method | Field |
| APL (Dyalog) | 3=x.⎕NC'method' | 2=x.⎕NC'method' | — | — |
| ABAP Objects | — | — | — | — |
| C++ | — | — | — | — |
| Objective-C (Cocoa) | [x respondsToSelector:@selector(method)] | — | forwardInvocation: | — |
| Smalltalk | x respondsTo: selector | — | doesNotUnderstand: | — |
| C# | (using reflection) | (using reflection) | (using reflection) | (using reflection) |
| eC | (using reflection) | (using reflection) | (using reflection) | (using reflection) |
| Java | (using reflection) | (using reflection) | (using reflection) | (using reflection) |
| D | | | opDispatch | opDispatch |
| Eiffel | — | — | — | — |
| Python | hasattr(x, "method") and callable(x.method) | hasattr(x, "field") | __getattr__ | __getattr__ |
| Visual Basic .NET | (using reflection) | (using reflection) | (using reflection) | (using reflection) |
| Xojo | (using Introspection) | (using Introspection) | (using Introspection) | (using Introspection) |
| Windows PowerShell | (using reflection) | (using reflection) | (using reflection) | (using reflection) |
| F# | (using reflection) | (using reflection) | (using reflection) | (using reflection) |
| Ruby | x.respond_to?(:method) | — | method_missing | — |
| PHP | method_exists(x, "method") | property_exists(x, "field") | __call | __get / __set |
| Perl | x->can("method") | exists x->{field} | AUTOLOAD | |
| Raku | x.can("method") | x.field.defined | AUTOLOAD | |
| OCaml | — | — | — | — |
| JavaScript | typeof x.method === "function" | field in x | | |
| COBOL | — | — | — | — |

## Special variables

| | current object | current object's parent object | null reference | Current Context of Execution |
| Smalltalk | self | super | nil | thisContext |
| ABAP Objects | me | super | initial | |
| APL (Dyalog) | ⎕THIS | ⎕BASE | ⎕NULL | |
| C++ | *this | | NULL, nullptr | |
| C# | this | base | null | |
| Java | this | super | null | |
| D | this | super | null | |
| JavaScript | this | super (ECMAScript 6) | null, undefined | |
| eC | this | | null | |
| Objective-C | self | super | nil | |
| Swift | self | super | nil | |
| Python | self | super(current_class_name, self) super (3.x only) | None | |
| Visual Basic .NET | Me | MyBase | Nothing | |
| Xojo | Me / Self | Parent | Nil | |
| Eiffel | Current | Precursor «{superclass}» «(args)» | Void | |
| PHP | $this | parent | null | |
| Perl | $self | $self->SUPER | undef | |
| Raku | self | SUPER | Nil | |
| Ruby | self | super«(args)» | nil | binding |
| Windows PowerShell | $this | | $NULL | |
| OCaml | self | super | — | |
| F# | this | base | null | |
| COBOL | SELF | SUPER | NULL | |
| Cobra | this | base | nil | |

## Special methods

| | String representation | String representation | Object copy | Value equality | Object comparison | Hash code | Object ID |
| | Human-readable | Source-compatible | Object copy | Value equality | Object comparison | Hash code | Object ID |
| ABAP Objects | — | — | — | — | — | — | — |
| APL (Dyalog) | ⍕x | ⎕SRC x | ⎕NS x | x = y | — | — |
| C++ | | | | x == y | | | pointer to object can be converted into an integer ID |
| C# | x.ToString | | x.Clone | x.Equals(y) | x.CompareTo(y) | x.GetHashCode | System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(x) |
| Java | x.toString | | x.clone | x.equals(y) | x.compareTo(y) | x.hashCode | System.identityHashCode(x) |
| JavaScript | x.toString | | | | | | |
| D | x.toString or std.conv.to!string(x) | x.stringof | | x == y or x.opEquals(y) | x.opCmp(y) | x.toHash | |
| eC | x.OnGetString(tempString, null, null) or PrintString(x) | | y.OnCopy(x) | | x.OnCompare(y) | | object handle can be converted into an integer ID |
| Objective-C (Cocoa) | x.description | x.debugDescription | [x copy] | [x isEqual:y] | [x compare:y] | x.hash | pointer to object can be converted into an integer ID |
| Swift | x.description | x.debugDescription | | x == y | x < y | x.hashValue | reflect(x).objectIdentifier!.uintValue |
| Smalltalk | x displayString | x printString | x copy | x = y | | x hash | x identityHash |
| Python | str(x) | repr(x) | copy.copy(x) | x == y | cmp(x, y) | hash(x) | 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 is COMPARABLE, one can simply do x < y | When x is HASHABLE, one can use x.hash_code | When x is IDENTIFIED, one can use x.object_id |
| PHP | $x->__toString | | clone x | x == y | | | spl_object_hash(x) |
| Perl | "$x" | Data::Dumper->Dump([$x],['x']) | Storable::dclone($x) | | | | Scalar::Util::refaddr( $x ) |
| Raku | ~x | x.perl | x.clone | x eqv y | x cmp y | | x.WHICH |
| Ruby | x.to_s | x.inspect | x.dup or x.clone | x == y or x.eql?(y) | 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.hash x | Oo.id x |
| F# | string x or x.ToString or sprintf "%O" x | sprintf "%A" x | x.Clone | x = y or x.Equals(y) | compare x y or x.CompareTo(y) | hash x or x.GetHashCode | |
| COBOL | — | — | — | — | — | — | — |

## Type manipulation

| | Get object type | Is instance of (includes subtypes) | Upcasting | Downcasting | Downcasting |
| | Get object type | Is instance of (includes subtypes) | Upcasting | Runtime check | No check |
| ABAP Objects | — | — | = | ?= |
| C++ | typeid(x) | dynamic_cast<type *>(&x) != nullptr | — | dynamic_cast<type*>(ptr) | (type*) ptr or static_cast<type*>(ptr) |
| C# | x.GetType | x is type | — | (type) x or x as type | |
| D | typeid(x) | | — | cast(type) x | |
| Delphi | | x is type | — | x as type | |
| eC | x._class | eClass_IsDerived(x._class, type) | — | | (type) x |
| Java | x.getClass | x instanceof class | — | (type) x | |
| Objective-C (Cocoa) | [x class] | [x isKindOfClass:[class class]] | — | | (type*) x |
| Swift | x.dynamicType | x is type | — | x as! type x as? type |
| JavaScript | x.constructor (If not rewritten.) | x instanceof class | — | — | — |
| Visual Basic .NET | x.GetType | TypeOf x Is type | — | CType(x, type) or TryCast(x, type) | |
| Xojo | Introspection.GetType(x) | x IsA type | — | CType(x, type) | — |
| Eiffel | x.generating_type | attached {TYPE} x | attached {TYPE} x as down_x | |
| Python | type(x) | isinstance(x, type) | — | — | — |
| PHP | get_class(x) | x instanceof class | — | — | — |
| Perl | ref(x) | x->isa("class") | — | — | — |
| Raku | x.WHAT | x.isa(class) | — | type(x) or x.type | |
| Ruby | x.class | x.instance_of?(type) or x.kind_of?(type) | — | — | — |
| Smalltalk | x class | x isKindOf: class | — | — | — |
| Windows PowerShell | x.GetType | x -is [type] | — | [type]x or x -as [type] | |
| OCaml | — | — | (x :> type) | — | — |
| F# | x.GetType | x :? type | (x :> type) | (x :?> type) | |
| COBOL | — | — | x AS type | — | — |

## Namespace management

| | Import namespace | Import namespace | Import item |
| | qualified | unqualified | Import item |
| 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 ns import * | from ns import item |
| PHP | | use ns; | use ns\item; |
| Perl | use ns; | | use ns qw(item); |
| Raku | use ns; | | |
| Ruby | | | |
| Windows PowerShell | | | |
| OCaml | | open ns | |
| F# | | open ns | |
| COBOL | — | — | — |

## Contracts

| | Precondition | Postcondition | Check | Invariant | Loop |
| ABAP Objects | — | — | — | — | — |
| C++ | — | — | — | — | — |
| C# | Spec#: type foo( «parameters» ) requires expression { body } | Spec#: type foo( «parameters» ) ensures expression { body } |
| Java | — | — | — | — | — |
| Objective-C | — | — | — | — | — |
| Visual Basic .NET | — | — | — | — | — |
| D | f in { asserts } body{ instructions } | f out (result) { asserts } body{ instructions } | assert(expression) | invariant { expression } | |
| Eiffel | f require tag: expression do end | f do ensure tag: expression end | f do check tag: expression end end | class X invariant tag: expression end | from instructions invariant tag: expression until expr loop instructions variant tag: expression end |
| Python | — | — | — | — | — |
| PHP | — | — | — | — | — |
| Perl | — | — | — | — | — |
| Raku | PRE { condition } | POST { condition } | | | |
| Ruby | — | — | — | — | — |
| Windows PowerShell | — | — | — | — | — |
| OCaml | — | — | — | — | — |
| F# | — | — | — | — | — |
| COBOL | — | — | — | — | — |