首页 > 编程语言 > 详细

[20-05-04][Thinking in Java 1]Java Inheritance 1 - Inheritance Syntax 2

时间:2020-05-04 11:48:38      阅读:40      评论:0      收藏:0      [点我收藏+]
 1 package test_1_1;
 2 
 3 public class A {
 4 
 5     /**
 6      * 初始化基类,构造器调动顺序
 7      */
 8     
 9     public A(int i){
10         System.out.println("this is A");
11     }
12 }

 

1 package test_1_1;
2 
3 public class B {
4 
5     public B(int i){
6         System.out.println("this is B");
7     }
8 }

 

 1 package test_1_1;
 2 
 3 public class C extends A{
 4 
 5     public C() {
 6         super(1);
 7         B b = new B(1);
 8         System.out.println("this is C");
 9     }
10     
11 }

 

 1 package test_1_1;
 2 
 3 public class Test {
 4 
 5     public static void main(String[] args) {
 6         
 7         C c = new C();
 8 
 9     }
10 
11 }

 

结果如下:

this is A
this is B
this is C

[20-05-04][Thinking in Java 1]Java Inheritance 1 - Inheritance Syntax 2

原文:https://www.cnblogs.com/mirai3usi9/p/12825870.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!