Defining Instance Methods

  1. Instance methods are methods that operate on an object.
    **** The definition of an instance method do NOT include the keyword static (static methods do not operate on objects)

  2. The access speficier public states that the method can be accessed (invoked) from any other methods.

  3. You have to specify a return type for every method.

    The return type can be:

  4. The method name is required.

    NOTE: the name alone does not uniquely identify a method in Java.
    You must include the parameters' type to identify a method.

  5. List of parameters:

    NOTE: method name PLUS parameters' type identify the method.


    Example:
           public class myClass
            {
              public void myMethod(int x)
    	   {
    	     ...
    	   }
    
              public void myMethod(double x)
    	   {
    	     ...
    	   }
    
              public void myMethod()            // No parameters...
    	   {
    	     ...
    	   }
            }
    
    Java will distinguish them as 3 different methods
    

  6. The method body is enclosed between {...}
    (Exactly like C/C++, Pascal: begin...end)