01.class Meal{
02. Meal() {
03. System.out.println("Meal()");
04. }
05.}
06.
07.class Bread{
08. Bread(){
09. System.out.println("Bread()");
10. }
11.}
12.
13.class Cheese{
14. Cheese() {
15. System.out.println("cheese()");
16. }
17.}
18.
19.class Lettuce{
20. Lettuce() {
21. System.out.println("Lettuce()");
22. }
23.}
24.
25.class Lunch extends Meal{
26. public Lunch() {
27. System.out.println("Lunch()");
28. }
29.}
30.
31.class PortableLunch extends Lunch{
32. public PortableLunch() {
33. System.out.println("portabkeLunch()");
34. }
35.}
36.
37.public class SandWich extends PortableLunch {
38. private Bread m =new Bread();
39. private Cheese s = new Cheese();
40. private Lettuce l = new Lettuce();
41.
42. SandWich(){
43. System.out.println("sandwich()");
44. }
45.
46. public static void main(String[] args) {
47. new SandWich();
48.
49. }
50.
51.}
52.
复制代码输出结果:
Meal()
Lunch()
portabkeLunch()
Bread()
cheese()
Lettuce()
sandwich()
为什么Bread() cheese() Lettuce() 会比sandwich() 先执行?? 感谢~~ |
|