Comparison of programming languages (object-oriented programming)
From Seo Wiki - Search Engine Optimization and Programming Languages
Jump to navigationJump to search
Template:ProgLangCompare This Comparison of programming languages compares how object-oriented programming languages such as C++, PHP, Perl and others manipulate data structures.
Object creation and destruction
creation | destruction | |
---|---|---|
ABAP Objects | data variable type ref to class . create object variable «exporting parameter = argument[1]». |
[2][3] |
C++ (STL) | class variable«(parameters)»; or class *variable = new class«(parameters)»; |
delete pointer; |
C# | class variable = new class(parameters); | variable.Dispose();[3] |
Java | variable.dispose();[3] | |
Objective-C | class *variable = [[class alloc ] init]; or class *variable = [[class alloc ] initWithFoo:parameter «bar:parameter ...»];
|
[variable release]; |
Python | variable = class(parameters) | del variable [3](Normally not needed) |
Visual Basic .NET | Dim variable As New class(parameters) | variable.Dispose()[3] |
Eiffel | create variable or create «{TYPE}» variable.make_foo «(parameters)» or variable := create {TYPE} or variable := create {TYPE}.make_foo «(parameters)» |
[3] |
PHP | $variable = new class(parameters); | unset($variable); |
Perl 5 | «my »$variable = class->new(parameters); | undef($variable); |
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» or let variable = object members end[4] |
[3] |
F# | let variable = «new »class(«parameters») |
File declaration
class | interface | 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. | Template:N/a |
C++ (STL) | class name« : public parentclasses[5]» { members }; | namespace name { members } | |
C# | class name« : parentclass«, interfaces»» { members } | interface name { members } | |
Java | class name« extends parentclass»« implements interfaces» { members } | package name; members | |
Objective-C | @interface name : parentclass «< protocols >» { instance_fields } method_and_property_declarations @end @implementation name method_implementations @end[6] |
@protocol name members @end | |
Python | class name(parentclasses[5]): Template:Keypress members |
[7] | __all__ = [ member1,member2,... ] |
Visual Basic .NET | Class name« Inherits parentclass»« Implements interfaces» members End Class |
Interface name members End Interface |
Namespace name members End Namespace |
Eiffel | class name« inherit parentclasses[5]» members end |
colspan=2 Template:N/a | |
PHP | class name« extends parentclass»« implements interfaces» { members } | interface name { members } | namespace name; members |
Perl | package name; «@ISA = qw(parentclasses[5]);» members 1; | package name; members | |
Ruby | class name« < parentclass» members end |
||
Windows PowerShell | colspan=3 Template:N/a | ||
OCaml | class name «parameters» = object «(self)» «inherit parentclass «parameters» «inherit parentclass «parameters» ...[5]»» members end | ||
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 |
Class members
Constructors and destructors
constructor | destructor | finalizer[8] | |
---|---|---|---|
ABAP Objects | methods constructor «importing parameter = argument» method constructor. instructions endmethod.[9] |
Template:N/a | |
C++ (STL) | class(«parameters») «: initializers[10]» { instructions } | ~class() { instructions } | |
C# | class(«parameters») { instructions } | void Dispose(){ instructions } | ~class() { instructions } |
Java | void dispose() { instructions } | void finalize() { instructions } | |
Eiffel | [11] | [12] | |
Objective-C | - (id)init { instructions... return self; } or - (id)initWithFoo:parameter «bar:parameter ...» { instructions... return self; } |
- (void)dealloc { instructions } | |
Python | def __init__(self«, parameters»): Template:Keypress instructions |
def __del__(self): Template:Keypress instructions | |
Visual Basic .NET | Sub New(«parameters») instructions End Sub |
Sub Dispose() instructions End Sub |
Overrides Sub Finalize() 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 } | |
Ruby | def initialize«(parameters)» instructions end |
Template:N/a | |
Windows PowerShell | colspan=3 Template:N/a | ||
OCaml | initializer instructions[13] | Template:N/a | |
F# | do instructions or new(parameters) = expression [14] |
member this.Dispose() = instructions | override this.Finalize() = instructions |
Fields
public | private | protected | friend | |
---|---|---|---|---|
ABAP Objects | public section.[15] data field type type. | private section.[15] data field type type. | protected section.[15] data field type type. | [16] |
C++ (STL) | public: type field; | private: type field; | protected: type field; | [17] |
C# | public type field «= value»; | private type field «= value»; | protected type field «= value»; | internal type field «= value»; |
Java | type field «= value»; | |||
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; |
Python | self.field = value Just assign a value to it in a method |
self.__field = value Just assign a value to it in a method |
colspan=2 Template:N/a | |
Visual Basic .NET | Public field As type «= value» | Private field As type «= value» | Protected field As type «= value» | Friend field As type «= value» |
PHP | public $field «= value»; | private $field «= value»; | protected $field «= value»; | |
Perl | $self->{field} = value; Just assign a value to it in a method |
colspan=3 Template:N/a | ||
Ruby | colspan=2 Template:N/a | @field = value Just assign a value to it in a method |
||
Windows PowerShell | Add-Member «-MemberType »NoteProperty «-Name »Bar «-Value »value -InputObject variable |
colspan=3 Template:N/a | ||
OCaml | colspan=2 Template:N/a | val «mutable» field = value | rowspan=2 Template:N/a | |
F# | Template:N/a | let «mutable» field = value | Template:N/a |
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.[18] |
[19] |
C++ (STL)[20] | void foo(«parameters») { instructions } | type foo(«parameters») { instructions ... return value; } |
C# | ||
Java | ||
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; } |
Python | def foo(self«, parameters»): Template:Keypress instructions |
def foo(self«, parameters»): Template:Keypress instructions Template:Keypress return value |
Visual Basic .NET | Sub Foo(«parameters») instructions End Sub |
Function Foo(«parameters») As type instructions ... Return value End Function |
PHP | function foo(«parameters») { instructions } | function foo(«parameters») { instructions ... return value; } |
Perl | sub foo { my ($self«, parameters») = @_; instructions } | sub foo { my ($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 | rowspan=2 Template:N/a | method foo «parameters» = expression |
F# | member this.foo(«parameters») = expression |
Properties
How to declare a property named "Bar"
Manually implemented
read-write | read-only | write-only | |
---|---|---|---|
ABAP Objects | colspan=3 Template:N/a | ||
C++ (STL) | colspan=3 Template:N/a | ||
C# | type Bar { get { instructions ... return value; } set { instructions } } |
type Bar { get { instructions ... return value; } } | type Bar { set { instructions } } |
Java | colspan=3 Template:N/a | ||
Objective-C | @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 } |
|
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): Template:Keypress instructions def getBar(self): Template:Keypress instructions Template:Keypress return value bar = property(getBar, setBar) |
def getBar(self): Template:Keypress instructions Template:Keypress return value bar = property(getBar) |
def setBar(self, value): Template:Keypress 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 |
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 | colspan=3 Template:N/a | ||
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 | colspan=3 Template:N/a | ||
F# | member this.Bar with get() = expression and set(value) = expression | member this.Bar = expression | member this.Bar with set(value) = expression |
Automatically implemented
read-write | read-only | write-only | |
---|---|---|---|
ABAP Objects | colspan=3 Template:N/a | ||
C++ (STL) | colspan=3 Template:N/a | ||
C# | type Bar { get; set; } | type Bar { get; private set; } | colspan=1 Template:N/a |
Java | colspan=3 Template:N/a | ||
Objective-C | @property (readwrite) type bar; and then inside @implementation @synthesize bar; |
@property (readonly) type bar; and then inside @implementation @synthesize bar; |
|
Eiffel | |||
Python | |||
Visual Basic .NET | Property Bar As type« = initial_value» (VB 10) | ||
PHP | |||
Perl | colspan=3 Template:N/a | ||
Ruby | attr_accessor :bar | attr_reader :bar | attr_writer :bar |
Windows PowerShell | |||
OCaml | colspan=3 Template:N/a | ||
F# |
Overloaded operators
Standard operators
unary | binary | |
---|---|---|
ABAP Objects | colspan=4 Template:N/a | |
C++ (STL) | type operatorsymbol() { instructions } | type operatorsymbol(type operand2) { instructions } |
C# | static type operator symbol(type operand) { instructions } | static type operator symbol(type operand1, type operand2) { instructions } |
Java | rowspan=2 colspan=2 Template:N/a | |
Objective-C | ||
Eiffel [21] | op_name alias "symbol": TYPE do instructions end |
op_name alias "symbol" (operand: TYPE1): TYPE2 do instructions end |
Python | def __opname__(self): Template:Keypress instructions Template:Keypress return value |
def __opname__(self, operand2): Template:Keypress instructions Template:Keypress 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 |
PHP | [22] | |
Perl | use overload "symbol" => sub { my ($self) = @_; instructions }; | use overload "symbol" => sub { my ($self, $operand2, $operands_reversed) = @_; instructions }; |
Ruby | def symbol instructions expression resulting in return value end |
def symbol(operand2) instructions expression resulting in return value end |
Windows PowerShell | rowspan=2 colspan=2 Template:N/a | |
OCaml | ||
F# | static member (symbol) operand = expression | static member (symbol) (operand1, operand2) = expression |
Indexers
read-write | read-only | write-only | |
---|---|---|---|
ABAP Objects | colspan=3 Template:N/a | ||
C++ (STL) | 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 } } |
Java | rowspan=2 colspan=4 Template:N/a | ||
Objective-C | |||
Eiffel [21] | 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): Template:Keypress instructions Template:Keypress return value def __setitem__(self, index, value): Template:Keypress instructions |
def __getitem__(self, index): Template:Keypress instructions Template:Keypress return value |
def __setitem__(self, index, value): Template:Keypress 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 | [23] | ||
Perl | colspan=3 Template:N/a | ||
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 | rowspan=2 colspan=3 Template:N/a | ||
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 |
Type casts
downcast | upcast | |
---|---|---|
ABAP Objects | colspan=2 Template:N/a | |
C++ (STL) | operator returntype() { instructions } | |
C# | static explicit operator returntype(type operand) { instructions } | static implicit operator returntype(type operand) { instructions } |
Java | rowspan=4 colspan=2 Template:N/a | |
Objective-C | ||
Eiffel [21] | ||
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 | rowspan=5 colspan=2 Template:N/a | |
Perl | ||
Ruby | ||
Windows PowerShell | ||
OCaml | ||
F# |
Member access
How to access members of an object x
object member | class member | namespace member | |||
---|---|---|---|---|---|
method | field | property | |||
ABAP Objects | x->method(«parameters[24]»). | x->field | Template:N/a | x=>field or x=>method(«parameters[24]»). | Template:N/a |
C++ (STL) | 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 ...»»] | |
C# | x.method(parameters) | x.field | x.property | cls.member | ns.member |
Java | Template:N/a | ||||
Python | x.property | ||||
Visual Basic .NET | |||||
Windows PowerShell | [cls]::member | ||||
F# | Template:N/a | cls.member | |||
Eiffel | x.method«(parameters)» | x.field | {cls}.member | rowspan=2 Template:N/a | |
Ruby | Template: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 | |
OCaml | x#method «parameters» | colspan=2 Template:N/a |
Member availability
Has member? | Handler for missing member | |||
---|---|---|---|---|
Method | Field | Method | Field | |
ABAP Objects | rowspan=2 colspan=4 Template:N/a | |||
C++ (STL) | ||||
Objective-C | [x respondsToSelector:@selector(method)] | Template:N/a | forwardInvocation: | Template:N/a |
C# | (using reflection) | |||
Java | ||||
Eiffel | colspan=4 Template:N/a | |||
Python | hasattr(x, "method") and callable(x.method) | hasattr(x, "field") | __getattr__() | |
Visual Basic .NET | (using reflection) | |||
Windows PowerShell | (using reflection) | |||
F# | (using reflection) | |||
Eiffel | colspan=4 Template:N/a | |||
Ruby | x.respond_to?(:method) | Template:N/a | method_missing() | Template:N/a |
PHP | method_exists(x, "method") | property_exists(x, "field") | __call() | __get() / __set() |
Perl | x->can("method") | defined x->{field} | AUTOLOAD | |
OCaml | colspan=4 Template:N/a |
Special variables
current object | current object's parent object | null reference | |
---|---|---|---|
Smalltalk | self | super | nil |
ABAP Objects | me | super | initial |
C++ (STL) | *this | [25] | NULL |
C# | this | base[26] | null |
Java | super[26] | ||
Objective-C | self | super | nil |
Python | self[27] | super(current_class_name, self)[5] super() (3.x only) |
None |
Visual Basic .NET | Me | MyBase | Nothing |
Eiffel | Current | Precursor «{superclass}» «(args)»[26][28] | Void |
PHP | $this | parent[26] | NULL |
Perl | $self[27] | $self->SUPER[26] | undef |
Ruby | self | super«(args)»[29] | nil |
Windows PowerShell | $this | $NULL | |
OCaml | self[30] | super[31] | Template:N/a[32] |
F# | this | base[26] | null |
Special methods
String representation | Object copy | Value equality | Object comparison | Hash code | Object ID | ||
---|---|---|---|---|---|---|---|
Human-readable | Source-compatible | ||||||
ABAP Objects | colspan=6 Template:N/a | ||||||
C++ (STL) | x == y[33] | ||||||
C# | x.ToString() | x.Clone() | x.Equals(y) | x.CompareTo(y) | x.GetHashCode() | ||
Java | x.toString() | x.clone()[34] | x.equals(y) | x.compareTo(y) | x.hashCode() | System.identityHashCode(x) | |
Objective-C | [x description] | [x copy][35] | [x isEqual:y] | [x compare:y][36] | [x hash] | ||
Python | str(x)[37] | repr(x)[38] | copy.copy(x)[39] | x == y[40] | cmp(x ,y)[41] | hash(x)[42] | 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 simply do x.hash_code | When x is IDENTIFIED, one can simply do x.object_id | |
PHP | sprintf("%s", x)[43] | clone x[44] | x == y | spl_object_hash(x) | |||
Perl | "$x"[45] | ||||||
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# | x.ToString() | sprintf "%A" x | x.Clone() | x.Equals(y) | x.CompareTo(y) | x.GetHashCode() |
Type manipulation
Get object type | Is instance of (includes subtypes) | Upcasting | Downcasting | |
---|---|---|---|---|
ABAP Objects | colspan=2 Template:N/a | = | ?= | |
C++ (STL) | typeid(x) | dynamic_cast<type *>(&x) != NULL | rowspan=6 Template:N/a[46] | (type) x or dynamic_cast<type*>(ptr) |
C# | x.GetType() | x is type | (type) x or x as type | |
Java | x.getClass() | x instanceof class | (type) x | |
Objective-C | [x class] | [x isKindOfClass:[class class]] | ||
Visual Basic .NET | x.GetType() | TypeOf x Is type | CType(x, type) or TryCast(x, type) | |
Eiffel | x.generating_type | attached {TYPE} x | attached {TYPE} x as down_x | |
Python | type(x) | isinstance(x, type) | colspan=2 rowspan=4 Template:N/a[47] | |
PHP | get_class(x) | x instanceof class | ||
Perl | ref(x) | x->isa("class") | ||
Ruby | x.class or x.type |
x.instance_of?(type) or x.kind_of?(type) | ||
Windows PowerShell | x.GetType() | x -is [type] | Template:N/a[46] | [type]x or x -as [type] |
OCaml | colspan=2 Template:N/a[48] | (x :> type) | Template:N/a | |
F# | x.GetType() | x :? type | (x :?> type) |
Namespace management
Import namespace | Import item | ||
---|---|---|---|
qualified | unqualified | ||
ABAP Objects | |||
C++ (STL) | using namespace ns; | using ns::item ; | |
C# | using ns; | ||
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; | ||
Ruby | |||
Windows PowerShell | |||
OCaml | open ns | ||
F# |
Contracts
Precondition | Postcondition | Check | Invariant | Loop | |
---|---|---|---|---|---|
ABAP Objects | colspan=5 rowspan=6 Template:N/a | ||||
C++ (STL) | |||||
C# | |||||
Java | |||||
Objective-C | |||||
Visual Basic .NET | |||||
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 | colspan=5 rowspan=7 Template:N/a | ||||
PHP | |||||
Perl | |||||
Ruby | |||||
Windows PowerShell | |||||
OCaml | |||||
F# |
See also
References and notes
- ↑ parameter = argument may be repeated if the constructor has several parameters
- ↑ SAP reserved to himself the use of destruction
- ↑ 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 This language uses garbage collection to release unused memory.
- ↑ OCaml objects can be created directly without going through a class.
- ↑ 5.0 5.1 5.2 5.3 5.4 5.5 This language supports multiple inheritance. A class can have more than one parent class
- ↑ Usually the
@interface
portion is placed into a header file, and the@interface
portion is placed into a separate source code file. - ↑ In Python interfaces are classes whose methods have pass as their bodies
- ↑ A finalizer is called by the garbage collector when an object is about to be garbage-collected. There is no guarantee on when it will be called or if it will be called at all.
- ↑ In ABAP, the constructor is to be defined like a method (see comments about method) with the following restrictions: the method name must be "constructor", and only "importing" parameters can be defined
- ↑ An optional comma-separated list of initializers for member objects and parent classes goes here. The syntax for initializing member objects is "member_name(parameters)" This works even for primitive members, in which case one parameter is specified and that value is copied into the member. The syntax for initializing parent classes is "class_name(parameters)". If an initializer is not specified for a member or parent class, then the default constructor is used.
- ↑ Any Eiffel procedure can be used as a creation procedure, aka constructors. See Eiffel paragraph at Constructor (computer science).
- ↑ Implementing {DISPOSABLE}.dispose ensures that dispose will be called when object is garbage collected.
- ↑ This "initializer" construct is rarely used. Fields in OCaml are usually initialized directly in their declaration. Only when additional imperative operations are needed is "initializer" used. The "parameters to the constructor" in other languages are instead specified as the parameters to the class in OCaml. See the class declaration syntax for more details.
- ↑ This syntax is usually used to overload constructors
- ↑ 15.0 15.1 15.2 Scope identifier must appear once in the file declaration, all variable declarations after this scope identifier have his scope, until another scope identifier or the end of class declaration is reached
- ↑ In ABAP, you don't declare specific fields or methods to be accessible by outside things. Rather, you declare outside classes to be friends to have access to the class's fields or methods.
- ↑ In C++, you don't declare specific fields to be accessible by outside things. Rather, you declare outside functions and classes to be friends to have access to the class's fields. See friend function and friend class for more details.
- ↑ The declaration and implementation of methods in ABAP are separate. methods statement is to be used inside the class definition. method (without "s") is to be used inside the class implementation. parameter = argument can be repeated if there are several parameters.
- ↑ In ABAP, the return parameter name is explicitly defined in the method signature within the class definition
- ↑ The declaration and implementation of methods in C++ are usually separate. Methods are declared inside the class definition (which is usually included in a header file) using the syntax
- type foo(«parameters»);
- type class::foo(«parameters») { instructions }
- ↑ 21.0 21.1 21.2 Although Eiffel does not support overloading of operators, it can define operators
- ↑ PHP does not support operator overloading natively, but support can be added using the "operator" PECL package.
- ↑ Your class needs to implement the ArrayAccess interface.
- ↑ 24.0 24.1 In ABAP, arguments must be passed using this syntax:
- x->method(«exporting parameter = argument» «importing parameter = argument» «changing parameter = argument» «returning value(parameter)»
- parameter = argument can be repeated if there are several parameters
- ↑ C++ doesn't have a "super" keyword, because multiple inheritance is possible, and so it may be ambiguous which base class is desired. Instead, you can use the
BaseClassName::member
syntax 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 not supported in other compilers.[1] - ↑ 26.0 26.1 26.2 26.3 26.4 26.5 The keyword here is not a value in itself and it can only be used to access a method of the superclass.
- ↑ 27.0 27.1 In this language, instance methods are passed the current object as the first parameter, which is conventionally named "self", but this is not required to be the case.
- ↑ "Precursor" in Eiffel is actually a call to the method of the same name in the superclass. So Precursor(args) is equivalent to "super.currentMethodName(args)" in Java. There is no way of calling a method of different name in the superclass.
- ↑ "super" in Ruby, unlike in other languages, is actually a call to the method of the same name in the superclass. So super(args) in Ruby is equivalent to "super.currentMethodName(args)" in Java. There is no way of calling a method of different name in the superclass.
- ↑ In OCaml, an object declaration can optionally start with a parameter which will be associated with the current object. This parameter is conventionally named "self", but this is not required to be the case. It is good practice to put a parameter there so that one can call one's own methods.
- ↑ In OCaml, an inheritance declaration ("inherit") can optionally be associated with a value, with the syntax "inherit parent_class «parameters» as super". Here "super" is the name we gave to the variable associated with this parent object. It can be named something else.
- ↑ However, if you really wanted the ability to have an "optional" value in OCaml, you would wrap the value inside an
option
type, whose values areNone
andSome x
, which could be used to represent "null reference" and "non-null reference to an object" as in other languages. - ↑ assuming that "x" and "y" are the objects (and not a pointer). Can be customized by overloading the object's
==
operator - ↑ Only accessible from within the class itself, since the
clone()
method inherited fromObject
is protected, unless the class overrides the method and makes it public. If you use theclone()
inherited fromObject
, your class will need to implement theCloneable
interface to allow cloning. - ↑ Implemented by the object's
copyWithZone:
method - ↑
compare:
is the conventional name for the comparison method in Foundation classes. However, no formal protocol exists - ↑ Can be customized by the object's
__str__()
method - ↑ Can be customized by the object's
__repr__()
method - ↑ Can be customized by the object's
__copy__()
method - ↑ Can be customized by the object's
__eq__()
method - ↑ Only in Python 2.x and before (removed in Python 3.0). Can be customized by the object's
__cmp__()
method - ↑ Can be customized by the object's
__hash__()
method. Not all types are hashable (mutable types are usually not hashable) - ↑ Can be customized by the object's
__toString()
method - ↑ Can be customized by the object's
__clone()
method - ↑ Can be customized by overloading the object's string-convertion operator
- ↑ 46.0 46.1 Upcasting is implicit in this language. A subtype instance can be used where a supertype is needed.
- ↑ Casting between types is not necessary.
- ↑ This language doesn't give run-time type information. It is unnecessary because it is statically typed and downcasting is not possible.
If you like SEOmastering Site, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...
→