-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathAccess.java
More file actions
39 lines (31 loc) · 709 Bytes
/
Access.java
File metadata and controls
39 lines (31 loc) · 709 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
package chapter8;
/* In a class hierarchy, private members remain private to their class
*
* This program contains an error and will not compile
* */
//Create a superclass
class A2 {
int i; //default access
private int j; //private to a
void setij(int x, int y) {
i = x;
j = y;
}
}
//A's j is not accessible here
class B2 extends A2 {
int total;
void sum() {
//total=i+j; Error j is not accessible here
total = i;
}
}
public class Access {
public static void main(String[] args) {
B2 subOb = new B2();
subOb.setij(10, 12);
subOb.sum();
System.out.println("Total is : ");
subOb.sum();
}
}