Call an object method: Difference between revisions

+Java
(+Java)
Line 56:
 
This last case can be useful when debugging.
=={{header|Java}}==
 
Static methods in Java are usually called by using the dot operator on a class name:
<lang java>ClassWithStaticMethod.staticMethodName(argument1, argument2);//for methods with no arguments, use empty parentheses</lang>
Instance methods are called by using the dot operator on an instance:
<lang java>ClassWithMethod varName = new ClassWithMethod();
varName.methodName(argument1, argument2);
//or
(new ClassWithMethod()).methodName(argument1, argument2);</lang>
Static methods can also be called using instances, but compilers usually complain about that. The call looks identical to an instance method call. Methods may not be called on uninitialized objects or objects initialized to <code>null</code> (throws a <code>NullPointerException</code>). <!--Maybe add reflection stuff here too? It might be too complicated or it might not belong here-->
=={{header|Python}}==
<lang python>>>> class MyClass():
Anonymous user