码迷,mamicode.com
首页 > 编程语言 > 详细

[20-05-04][Thinking in Java 6]Java Inheritance 4 - Upcasting

时间:2020-05-04 15:05:51      阅读:57      评论:0      收藏:0      [点我收藏+]

标签:string   str   super   stat   rgs   show   xtend   bsp   pca   

 1 package test_1_4;
 2 
 3 public class Amphibian {
 4 
 5     public Amphibian(int i) {
 6         
 7         System.out.println("this is Amphibian");
 8     }
 9     
10     public void print(Amphibian i) {
11         
12         System.out.println("print Amphibian");
13         show();
14     }
15     
16     public void show() {
17         
18         System.out.println("show");
19     }
20     
21 }

 

 1 package test_1_4;
 2 
 3 public class Frog extends Amphibian{
 4     
 5     public Frog(int i) {
 6         
 7         super(i);
 8         System.out.println("this is frog");
 9     }
10     
11     public static void main(String[] args) {
12         
13         Frog frog = new Frog(1);
14         frog.print(frog);
15     }
16 }

 

结果如下:

this is Amphibian
this is frog
print Amphibian
show

[20-05-04][Thinking in Java 6]Java Inheritance 4 - Upcasting

标签:string   str   super   stat   rgs   show   xtend   bsp   pca   

原文地址:https://www.cnblogs.com/mirai3usi9/p/12826312.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!