-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackages.java
More file actions
58 lines (45 loc) · 1.6 KB
/
Packages.java
File metadata and controls
58 lines (45 loc) · 1.6 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.company;
class A {
public int x = 5;
protected int y = 77;
int z = 19;
private int a = 6;
public void methA() {
System.out.println("\nAccessing the properties from the same class: ");
System.out.println("Public = " + x);
System.out.println("Protected = " + y);
System.out.println("Default = " + z);
System.out.println("Private = " + a);
}
}
class B extends A {
public void methB() {
System.out.println("\nAccessing the properties from the sub-class in the same package: ");
System.out.println("Public = " + x);
System.out.println("Protected = " + y);
System.out.println("Default = " + z);
// System.out.println(a);
}
}
public class Packages {
public int x = 5;
protected int y = 77;
int z = 19;
private int a = 6;
public static void main(String[] args) {
/* Modifiers Class Package Sub-class World
Public Y Y Y Y
Protected Y Y Y N
Default Y Y N N
Private Y N N N */
A a = new A();
a.methA();
B b = new B();
b.methB();
System.out.println("\nAccessing the properties of a class form another class but in the same package: ");
System.out.println("Public = " + a.x); // x is Public
System.out.println("Protected = " + a.y); // y is Protected
System.out.println("Default = " + a.z); // z is Default
// System.out.println(a.a); // a is Private
}
}