Parametrized Method Example Java Program


Definition

A method (or message) in object-oriented programming (OOP) is a procedure associated with an object class. An object is made up of behaviour and data. Data is represented as properties of the object and behavior as methods. Methods are also the interface an object presents to the outside world. A parameterised method holds variables.

Syntax

access_specifier return_type method_name(data_type variable_name, data_type variable_name){
	//Statements
}

Parametrized Method Example Program

public class ParametrizedMethod{
	public static void main(String[] args) {
		int num1 = 11;
		int num2 = 6;
		int num3 = minValue(num1, num2);
		System.out.println("Minimum Value while comparison of num 1 and num2 is = " + num3);
	}
	public static int minValue(int i, int j) {
		int min;
		if (i > j){
			min = j;
		}
		else{
			min = i;
		}
		return min; 
	}
}

Sample Output

Output is:
Minimum Value while comparison of num1 and num2 is = 6