Sample Programs in java

Java Example Program to explain Pass By value to a method

[java]
/* Program for pass by value*/
/**
*@author:Candidjava.com
*@Description: passing values to method
*/

public class form
{
String name;
int age;
String gender;
int exp;
int sal;
void setData(String n,int a,String g,int e,int s)
{
name=n;
age=a;
gender=g;
exp=e;
sal=s;
}
void print()
{
System.out.println(name);
System.out.println(age);
System.out.println(gender);
System.out.println(exp);
System.out.println(sal);
}
}

public class Main
{
public static void main(String args[])
{
form f1=new form();
f1.setData("Ars",25,"m",3,22000);
f1.print();
}
}
[/java]

Table of Contents

Output:

Ans
25
m
3
22000