Method

A method is a function that is a member of a class and may operate on an object.

Related concepts:  FunctionMemberClassObject

Closest Wikipedia entry:  Method (computer programming) — A method in object-oriented programming (OOP) is a procedure associated with an object, and generally also a message. An object consists of state data and behavior; these compose an interface, which specifies how the object may be used. A method is a behavior of an object parametrized by a user.

Authoritative Definition

Wikipedia does not necessarily offer the best fitting definition of a concept. The exact meaning we attribute to the concept of Method is based on principled authoritative sources such as:

Misconceptions about Method
49 documented Misconceptions

Check Yourself
Misconception
AddMemberAtRuntimeJava
Set of class members can change at runtime
Misconception
ArrayHasLengthMethodJava
To get the length of an array, one needs to call its length method
Misconception
BaseCaseNotNeededJava
Recursive computations do not necessarily need a base case
Misconception
BaseCaseSelfRecursiveJava
The base case of a structural recursion consists of a recursive self-call
Misconception
CallNotStaticallyCheckedJava
A method invocation on a reference of a type that does not have that method won't compile
Misconception
CallOnPrimitiveJava
One can invoke a method on primitive values
Misconception
CallRequiresVariableJava
One needs a variable to invoke a method
Misconception
CallWithoutFrameJava
A method invocation does not necessarily allocate a stack frame
Misconception
CallerFrameContainsCalleeFormalJava
Stack frame of caller includes variables for callee's formal parameters
Misconception
CannotChainAttributeToObjectInstantiationPython
Method calls, and attribute accesses in general, cannot be chained to a constructor invocation.
Misconception
CannotChainMemberAccessesJava
Member accesses cannot be chained together
Misconception
CannotChainMemberToConstructorJava
Method calls or field accesses cannot be chained to a constructor invocation
Misconception
ChainedMethodsNotCalledFromOutsideJava
Chained methods are all called on the object at the beginning of the chain
Misconception
ConcreteClassMustOverrideJava
A concrete class needs to implement all methods declared in its abstract superclasses
Misconception
ConcreteClassOnlyImplementClassAbstractJava
A concrete class only needs to implement those abstract methods it inherits from abstract superclasses
Misconception
ConcreteClassOnlyImplementDirectAbstractJava
A concrete class only needs to implement abstract methods declared in its direct supertypes
Misconception
ConcreteClassOnlyImplementInterfaceAbstractJava
A concrete class only needs to implement those abstract methods it inherits from interfaces
Misconception
DeferredReturnJava
A return statement in the middle of a method doesn't return immediately
Misconception
EqualsComparesReferencesJava
o.equals(p) compares the references stored in the variables o and p
Misconception
ImmutableRequiresFinalParametersJava
Immutable classes need final constructor/method parameters
Misconception
ImplicitInterfaceImplementationJava
Java implicitly produces implementations of any methods a class inherits from the interfaces it implements
Misconception
InterproceduralEdgeJava
In an intra-procedural control-flow graph, method call nodes point to the called method
Misconception
MethodAsFieldJava
Each object contains its own special fields for all of its methods
Misconception
MethodWithoutReturnTypeJava
A method declaration does not need to include a return type
Misconception
MethodsWithoutClassJava
Methods can be defined outside a class
Misconception
NoCallOnStringLiteralJava
One cannot invoke methods on String literals
Misconception
NoInsideMethodCallInConstructorJava
It is foirbidden to call other methods on the same object while inside its constructor
Misconception
NoMethodInheritanceJava
Subclasses inherit fields but not methods
Misconception
NoStringToStringJava
One cannot invoke toString() on a String
Misconception
OutsideInMethodNestingJava
Nested method calls are invoked outside in
Misconception
ParenthesesOnlyIfArgumentJava
() are optional for method calls without arguments
Misconception
PrivateAccessibleInSubclassJava
Private members of a superclass are accessible from a subclass
Misconception
RecursiveMethodImpliesRecursiveTypeJava
A class with a recursive method represents part of a recursive data structure
Misconception
RecursiveMethodNeedsIfElseJava
A recursive method needs to contain an if-else statement
Misconception
ReturnCallJava
Return statements need () around the return value
Misconception
RightToLeftChainingJava
Chained accesses are invoked from right to left
Misconception
RightToLeftChainingPython
Chained accesses are invoked from right to left
Misconception
SetterIsStaticJava
Setter methods are static
Misconception
StackTraceIsCallHistoryJava
A stack trace is the sequence of previously called methods
Misconception
StaticCallPolymorphicJava
A static method call is dispatched polymorphically at runtime based on the argument types
Misconception
StaticDispatchJava
The method to be called is determined by the static type
Misconception
StaticFrameInGlobalsJava
Stack frame of static method calls lives in the global memory area
Misconception
StringLengthFieldJava
One can know the length of a String object by accessing its length field
Misconception
ThisChildInCallExpressionJava
Instance method or constructor call nodes in expression trees have a child labeled "this"
Misconception
ThisExistsInStaticMethodJava
this is a local variable, also in static methods
Misconception
ToStringPrintsJava
Invoking toString() prints something
Misconception
UseOfSelfTypeImpliesRecursiveTypeJava
If a class has a method that has a local variable, parameter, or return value with the class as its type, the class is a recursive type
Misconception
VoidMethodNotRecursiveJava
A method with void return type can't be recursive
Misconception
VoidMethodReturnsValueJava
A method with void return type can return a value

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.