What is Method in Java? | Core Java Tutorials

This Core Java Tutorials “Introduction to methods in java” post is providing clear information about definition of method, calling method, classification of methods and much more.


 

Method:

  • A block of instructions having Identity.
  • Every method is taking input, processing input and returns output.
  • Input is called “Arguments list”
  • Output is called “Return type”
  • We must place processing logic inside a block is called “body of method”.
  • Every method must be called explicitly (using its identity).

 

  • Every method is having 2 things.
    1. Method Definition.
    2. Method call.
  • Method definition is a block of instructions where we define logic.
  • Method call is a single statement used to invoke the method in the application.

 

Why we need to call a method explicitly?

  • Look at the example shown in the diagram.
  • Every electronic device (object) having much inbuilt functionality.
  • But the functionality of any object will not execute automatically(tv will not be controlled itself)
  • Another object (controller) is required to access functionality of any object.

 

Classification of Methods:

  1. No arguments(input) and No return values(output)
  2. With arguments and No return values
  3. With arguments and With return values
  4. No arguments and With return values

Share this