Method Calls

 

Python

Java

 

An instance method call consists of an object reference (also called the receiver object), followed by a dot, followed by the method name, followed by a parenthesized list of arguments.

 

Example:

 

aList.sort()

 

A class method call consists of a class name, followed by a dot, followed by the method name, followed by a parenthesized list of arguments.

 

 

 

 

 

A method returns the type of value indicated by its return statement, if one exists.  If a method does not explicitly return a value, the value None is returned by default.  Type compatibilities are resolved at run time.

 

An instance method call typically consists of an object reference (also called the receiver object), followed by a dot, followed by the method name, followed by a parenthesized list of arguments..

 

Example:

 

aList.set(3, 45)

 

A class method call consists of a class name, followed by a dot, followed by the method name, followed by a parenthesized list of arguments.

 

Example:

 

double d = Math.sqrt(2)

 

All methods are defined to return a specific type of value.  When the return value is not expected, the methodŐs return type is void.  Otherwise, the type of value returned must be compatible, at compile time, with the type of value expected (the example shows an assignment of a double to a double).

 

Previous

Index

Next