type foo(«parameters») { instructions ... return value; }
C#
Java
JavaScript
function foo(«parameters») { instructions }; or var foo = function («parameters») { instructions }; or var foo = new Function («"parameters1", "parameters2", ..., »"instructions");
function foo(«parameters») { 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
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
^ 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.
^ ab This is a finalizer rather than a destructor. It 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.
^ 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.
^ 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.
^ Where casttype is either Widening(may not cause data loss) or Narrowing(data loss possible).
^ Microsoft Visual C++ provides a non-standard keyword "__super" for this purpose; but this is not supported in other compilers because multiple inheritance is possible in C++.[1]
^ abcd The keyword here is not a value in itself and it can only be used to access a method of the superclass.
^ ab 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.
^ "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 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.
^ abc Upcasting is implicit in this language. A subtype instance can be used where a supertype is needed.
^ ab This is a dynamically-typed language. Casting between types is unnecessary.
^ This language has no run-time type information. It is unnecessary as it is statically typed and downcasting is not possible.