Here we make a swap method to interchange the information of two employees using Employee Objects by passing them to swap() method.
Here is the source code of the Java Program to Interchange Two Employee Objects by Passing them to Swap() Method. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Swap_Demo
static String emp1, emp2;
emp1 = "this is A";
emp2 = "this is B";
void swap(String x,String y)
res = x;
x = y;
y = res;
public static void main(String args)
Swap_Demo obj = new Swap_Demo();
$ javac Swap_Demo.java $ java Swap_Demo Before swapping: Employee1:this is A Employee2:this is B After swapping: Employee1: this is B Employee2: this is A
Sanfoundry Global Education & Learning Series – 1000 Java Programs.