Skip to content

Commit a997179

Browse files
main
1 parent f777b6d commit a997179

File tree

5 files changed

+102
-2
lines changed

5 files changed

+102
-2
lines changed

10.String/StringClassCodes/program2.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ public static void main(String[] args) {
1717

1818
//Identity HashCode
1919

20-
21-
2220
System.out.println(System.identityHashCode(str4));
2321
System.out.println(System.identityHashCode(str5));
2422
System.out.println(System.identityHashCode(ch));
1004 Bytes
Binary file not shown.
Binary file not shown.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package AccessSpecifiers;
2+
3+
class Demo{
4+
int x = 10;
5+
private int y =20;
6+
7+
void fun(){
8+
System.out.println(x);
9+
System.out.println(y);
10+
}
11+
}
12+
13+
class mainDemo{
14+
public static void main(String[] args) {
15+
Demo obj = new Demo();
16+
obj.fun();
17+
18+
// System.out.println(obj.x);
19+
// System.out.println(obj.y);
20+
21+
// System.out.println(x);
22+
// System.out.println(y);
23+
}
24+
}
25+
26+
27+
/*
28+
29+
Output:
30+
31+
program2.java:19: error: y has private access in Demo
32+
System.out.println(obj.y);
33+
^
34+
program2.java:21: error: cannot find symbol
35+
System.out.println(x);
36+
^
37+
symbol: variable x
38+
location: class mainDemo
39+
program2.java:22: error: cannot find symbol
40+
System.out.println(y);
41+
^
42+
symbol: variable y
43+
location: class mainDemo
44+
3 errors
45+
error: compilation failed
46+
47+
48+
*/
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package AccessSpecifiers;
2+
3+
class employee{
4+
int empId = 10;
5+
String empName = "Raj";
6+
static int salary = 5000;
7+
8+
void empInfo(){
9+
System.out.println("empId"+empId);
10+
System.out.println("empName: "+empName);
11+
System.out.println("Salary: "+salary);
12+
}
13+
}
14+
15+
class Empdetails{
16+
public static void main(String[] args) {
17+
employee emp1 = new employee();
18+
employee emp2 = new employee();
19+
20+
emp1.empInfo();
21+
emp2.empInfo();
22+
23+
System.out.println(System.identityHashCode(emp1.empName));
24+
System.out.println(System.identityHashCode(emp2.empName));
25+
26+
27+
System.out.println(System.identityHashCode(emp1.empId));
28+
System.out.println(System.identityHashCode(emp2.empId));
29+
30+
System.out.println(System.identityHashCode(emp1.salary));
31+
System.out.println(System.identityHashCode(emp2.salary));
32+
33+
34+
System.out.println();
35+
36+
emp1.empId = 20;
37+
emp1.empName = "Rahul";
38+
emp1.salary = 2000;
39+
40+
emp1.empInfo();
41+
emp2.empInfo();
42+
43+
System.out.println(System.identityHashCode(emp1.empName));
44+
System.out.println(System.identityHashCode(emp2.empName));
45+
46+
System.out.println(System.identityHashCode(emp1.empId));
47+
System.out.println(System.identityHashCode(emp2.empId));
48+
49+
System.out.println(System.identityHashCode(emp1.salary));
50+
System.out.println(System.identityHashCode(emp2.salary));
51+
52+
53+
}
54+
}

0 commit comments

Comments
 (0)