forked from janzolau1987/study-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeetle.java
More file actions
41 lines (33 loc) · 840 Bytes
/
Beetle.java
File metadata and controls
41 lines (33 loc) · 840 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
40
41
package com.yaoyaohao.study.initial;
/**
* 带有继承关系的对象初始化
*
* @author liujianzhu
* @date 2016年5月12日 下午5:05:43
*
*/
class Insect {
private int i = 9;
protected int j;
Insect() {
System.out.println("i = " + i + " j = " + j);
j = 39;
}
private static int x1 = printInit("static Insect.x1 initialized");;
static int printInit(String s) {
System.out.println(s);
return 47;
}
}
public class Beetle extends Insect {
private int k = printInit("Beetle.k initialized");
public Beetle() {
System.out.println("k = " + k);
System.out.println("j = " + j);
}
private static int x2 = printInit("static Beetle.x2 initialized");
public static void main(String[] args) {
System.out.println("Beetle constructor");
Beetle b = new Beetle();
}
}