Java Lab Mannual
Java Lab Mannual
Output:
10
11
12
13
14
15
17
18
19
20
Program:
class Number {
int x;
}
class CallByReference {
public static void main ( String[] args ) {
Number a = new Number();
a.x=3;
System.out.println("Value of a.x before calling increment() is "+a.x);
increment(a);
System.out.println("Value of a.x after calling increment() is "+a.x);
}
public static void increment(Number n) {
System.out.println("Value of n.x before incrementing x is "+n.x);
n.x=n.x+1;
System.out.println("Value of n.x after incrementing x is "+n.x);
}
}
Output:
21
Output:
22
23
25
27
28
Output:
29
30
31
32
33
34
35
36
37
38
39
40
41
43
44
45
46
50
51
52
56
57
58
59
60