File tree Expand file tree Collapse file tree 5 files changed +102
-2
lines changed
10.String/StringClassCodes
11.Classes&Objects/AccessSpecifiers Expand file tree Collapse file tree 5 files changed +102
-2
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,6 @@ public static void main(String[] args) {
17
17
18
18
//Identity HashCode
19
19
20
-
21
-
22
20
System .out .println (System .identityHashCode (str4 ));
23
21
System .out .println (System .identityHashCode (str5 ));
24
22
System .out .println (System .identityHashCode (ch ));
Original file line number Diff line number Diff line change
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
+ */
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments