-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathSingleLevel.java
More file actions
62 lines (50 loc) · 1.21 KB
/
SingleLevel.java
File metadata and controls
62 lines (50 loc) · 1.21 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
59
60
61
62
package Inheritance;
class A {
private int i = 12;
protected int j = 13;
public int k = 14;
int m = 3;
A() {
System.out.println("I'm Constructor from class A.");
}
private void m1() {
System.out.println("Private method of class A " + i);
}
protected void m2() {
System.out.println("Protected method of class A " + j);
m1();
}
public void m3() {
System.out.println("Public method of class A " + k);
}
void m4() {
System.out.println("Package method of class A" + i + " " + m);
}
}
class B extends A {
B() {
System.out.println("I'm Constructor from class B.");
}
public void m5() {
// System.out.println(i); // private variables not accessible in
// sub-class
System.out.println(" Method from class B. ");
System.out.println("Protected j= " + j);
System.out.println("public k= " + k);
System.out.println("Package m= " + m);
// m1(); // Private method is not accessible in sub-class
m2();
m3();
m4();
}
}
public class SingleLevel {
public static void main(String[] args) {
B b = new B();
System.out.println("----------------------------------");
System.out.println(" From Main method. ");
b.m5();
b.m4();
System.out.println("----------------------------------");
}
}