-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoSwap.java
More file actions
61 lines (55 loc) · 1.1 KB
/
DemoSwap.java
File metadata and controls
61 lines (55 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* WAP to swap the values of two different classes*/
import java.util.*;
class First
{
int no1;
void input1()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter first value");
no1 = sc.nextInt();
}
void show1()
{
System.out.println("Value of no1= "+no1);
}
}
class Second
{
int no2;
void input2()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter second value");
no2 = sc.nextInt();
}
void show2()
{
System.out.println("Value of no2= "+no2);
}
}
class DemoSwap
{
void swap(First ob1,Second ob2)
{
int temp;
temp = ob1.no1;
ob1.no1 = ob2.no2;
ob2.no2 = temp;
}
public static void main(String args[])
{
First ob1 = new First();
ob1.input1();
Second ob2 = new Second();
ob2.input2();
System.out.println("Before swapping the values are");
ob1.show1();
ob2.show2();
DemoSwap ob3 = new DemoSwap();
ob3.swap(ob1,ob2);
System.out.println("After the swapping the values are");
ob1.show1();
ob2.show2();
}
}