Tuesday, November 18, 2008

call function with parameters

In the last lession you learned how to create a method and call it from main method. This time you will learn how to create a method with parameter and call it from main method.

**********************************************************
public class FunctionCall {
public static void function1(){
System.out.println("Message from outside method");
}

public static void function2(int param){
System.out.println("Inside a function with parameter"+param);
}

public static void main(String[] args) {
System.out.println("Inside the main");
System.out.println("About to call function1");
function1();
System.out.println("About to call function2");
function2(2008);
}

}
********************************************************

You will get output like below, after execute the above programe
---------------------------------------
Inside the main
About to call function1
Message from outside method
About to call function2
Inside a function with parameter2008
---------------------------------------

No comments: