forked from solvery/lang-features
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoo_1.java
More file actions
86 lines (70 loc) · 1.35 KB
/
Copy pathoo_1.java
File metadata and controls
86 lines (70 loc) · 1.35 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class Base {
{
foo = 12;
}
public int foo = 5;
public int bar = 5;
static{
System.out.println("static initial block.");
}
{
System.out.println("initial block.");
}
public Base() {
System.out.println("Base()");
}
public Base(int a) {
System.out.println("Base(int) " + a);
}
public void todo() {
System.out.println("in base.");
}
}
public class oo_1 extends Base {
public int foo;
// constractor
public oo_1() {
int foo = 0;
this.foo = 6;
}
public oo_1(int i) {
super(2);
}
// overload
public void test() {
System.out.println("no args");
}
public void test(String msg) {
System.out.println("" + msg);
}
public void test(String... msg ) {
for (String s : msg) {
System.out.println(s);
}
}
// override
public void todo() {
System.out.println("in oo.");
super.todo();
}
// super
public void accessBase() {
System.out.println(super.foo);
}
public static void main(String[] args) {
oo_1 o1 = new oo_1();
oo_1 o3 = new oo_1(2);
oo_1 o2;
o2 = new oo_1();
System.out.println(new oo_1().foo);
o2.test();
o2.test("hello");
o2.test(new String[]{"he","he"});
System.out.println(o2.foo);
o2.accessBase();
System.out.println(o2.bar);
o2.bar = 3;
System.out.println(o2.bar);
o2.todo();
}
}