3:53 am - Tuesday February 20, 2018

Java Example Program to explain Pass By value to a method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/* 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();
}
}

Output:

Ans
25
m
3
22000

Filed in: Sample Programs in java

Comments are closed.