What is Method in Java Programming

Today we will learn, What is Method in Java Programming. A method is a set of code which is referred to by name and can be called at any point in java program by utilizing the method’s name.  You can say the method is a subprogram that acts on data and often returns a value. Java methods must be located inside a Java class.

Each method must have its own name.  When method name is encountered in a program, the execution of the method starts.  When the method is finished, execution returns to the area of the program code from which method was called, and the program continues execution of next line of code.

In the above example, FirstMethod is the method name, public is access modifier in Java, the void is return type.


Method Return Types

A Java Method can return a value. Method return type signals what kind of value method will return.

Example –

In above example, int is indicating that method will return the integer type value. The second return statement is determined, what value is returned by the method, the here method is returning the “value” variable.

  •  You can’t declare more than one return statement in one method.
  • the return statement should be the last statement in the method.
  • The variables declared inside the method body are called the local variable.
  • You can call the method with its name only.
  • The method must have the body.
  • The method can accept the “n” number of parameters.
  • Methods access modifiers define the access level of method.
  • If the method has n number of parameter then it’s the must to pass all parameter in method body while calling the method in program code.
  • the return type is the must in a method, you can’t declare the method without its return type.
  • If the return type is null it means method will not return any value.


Selenium Testing Video Tutorial:

1 Comment
  1. Rajeev 10:06 AM / August 24, 2016 - Reply

    Nice explain ….

Leave a Reply