bing
Flat 10% & upto 50% off + Free additional Courses. Hurry up!

Java Methods

 

It is a collection of statement which is used to perform some operation. The main benefit to use method is that it provides code reusability. Once a method is created, then it can be reused multiple times as per requirements.

 

Creating Method

To create a method following syntax is used:

Access_modifier Return_type Method_name (Parameter_list) {

//Body of method

}

Where,

Access_modifier: It defines the access type of methods like private, public, protected.

Return_type: Specify the return type of method.

Method_name: It shows the name of method.

Parameter _list: Contains a list of parameters with their type. A method contains either zero parameter or more than 0 parameters.

Body of method: Contains the statements which perform some operation.

Example:

public static int sum(int i, int j) {

int total;

total = i + j;

return total;

}

 

To call the method following syntax is used:

Method_name(Parameter_list);

Example:

public class Intellipaat{

public static void main(String[] args) {

int a = 10;

int b = 20;

int c = sum(a, b);

System.out.println("Sum of two numbers = " + c);

}

public static int sum(int i, int j) {

int total;

total = i + j;

return total;

}

}

Learn more about Cross-Platform Mobile Technology for Android and iOS using Java in this insightful blog now!

"0 Responses on Java Methods"

Training in Cities

Bangalore, Hyderabad, Chennai, Delhi, Kolkata, UK, London, Chicago, San Francisco, Dallas, Washington, New York, Orlando, Boston

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.

top

Sales Offer

  • To avail this offer, enroll before 05th December 2016.
  • This offer cannot be combined with any other offer.
  • This offer is valid on selected courses only.
  • Please use coupon codes mentioned below to avail the offer
offer-june

Sign Up or Login to view the Free Java Methods.