-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPassByValue.java
More file actions
41 lines (36 loc) · 846 Bytes
/
PassByValue.java
File metadata and controls
41 lines (36 loc) · 846 Bytes
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
// to run: javac PassByValue.java && java PassByValue
class PassByValue{
public static void main(String[] args){
emp a=new emp("a");
emp b=new emp("b");
foo(a,b);
System.out.println(a);
System.out.println(b);
char ac='a';
char bc='b';
bar(ac,bc);
System.out.println(ac);
System.out.println(bc);
}
private static void foo(emp a,emp b){
a.setName("1");
b=new emp("2");
System.out.println("This is inside foo method "+b);
}
private static void bar(char a,char b){
a = 'q';
b = 'e';
}
}
class emp{
String name;
public emp(String name){
this.name=name;
}
public void setName(String name){
this.name=name;
}
public String toString(){
return name;
}
}