File tree 3 files changed +54
-0
lines changed
3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ class PassByValue1 {
2
+ public static void main (String [] args ) {
3
+ int i =0 ;
4
+ change (i );
5
+ System .out .println ("i=" +i );
6
+ }
7
+ public static void change (int i )
8
+ {
9
+ i =10 ;
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ class A
2
+ {
3
+ int a ;
4
+ A (int i )
5
+ {
6
+ a =i ;
7
+ }
8
+ }
9
+ public class PassingObjects1 {
10
+ public static void main (String [] args ) {
11
+
12
+
13
+ A obj =new A (100 );
14
+ change (obj );
15
+ System .out .println ("a=" +obj .a );
16
+ }
17
+ static void change (A obj1 )
18
+ {
19
+ obj1 =new A (10 );
20
+ }
21
+
22
+ }
Original file line number Diff line number Diff line change
1
+ class A {
2
+ int a ;
3
+
4
+ A (int i ) {
5
+ a = i ;
6
+ }
7
+ }
8
+
9
+ public class PassingObjects2 {
10
+ public static void main (String [] args ) {
11
+
12
+ A obj = new A (100 );
13
+ change (obj );
14
+ System .out .println ("a=" + obj .a );
15
+ }
16
+
17
+ static void change (A obj1 ) {
18
+ obj1 .a =10 ;
19
+ }
20
+
21
+ }
You can’t perform that action at this time.
0 commit comments