public class test {
static class father {
void run() {
System.out.println("father run");
}
}
static class son extends father{
void run() {
System.out.println("son run");
}
} public void sayHello(son son) {
System.out.println("son");
} public void sayHello(father father) {
System.out.println("father");
} public static void main(String[] args) {
father a = new son();
a.run();
test t = new test();
t.sayHello(a);
System.out.println(a.getClass());
}
}

输出结果:

son run
father
class old.test$son

解释:

father a = new son()

这里面 father 是静态类型,son是实际类型。

静态类型是在编译期可知的,而实际类型是在运行期才可以知道,

所以当运行run()时,取的是子类方法,而将a作为参数传入时,是以father这个类型传入的。

这也说明了重写载是静态的,而重写是动态的。

最新文章

  1. 在centos6.5中安装jdk
  2. mvc+ef+oracle环境中报错:ORA-00001: 违反唯一约束条件
  3. dictionary ----- python
  4. kafka入门教程
  5. HDOJ 2736 Surprising Strings
  6. finally块执行时间
  7. UEditor上传图片到七牛C#(后端实现)
  8. 开源自己写的一个拖拽库,兼容到IE8+
  9. SQL注入攻击[详解]
  10. Who do you want to be bad? (谁会是坏人?)人工智能机器小爱的问话
  11. arcgis api 3.x for js 入门开发系列二十二地图模态层(附源码下载)
  12. stackExchange.redis 实现模糊匹配批量查询
  13. Redis之分布式锁
  14. POJ 3264 线段树入门解题报告
  15. Delphi IdTCPClient IdTCPServer 点对点传送文件
  16. S4 继承
  17. JavaEE之反射
  18. ToggleButton开关状态按钮控件
  19. PHPCMS分页原理
  20. oracle用户和权限

热门文章

  1. 双屏显示——NW.js
  2. 自定义Spring-Boot @Enable注解
  3. NOIP2013提高问题求解T2(关于递推与递归)
  4. python 生成器、三元表达式、列表推倒式、字典生成式、生成器表达式(总结)
  5. 交换机安全学习笔记 第五章 DHCP缺陷攻击
  6. MySQL-线上数据迁移实战记录
  7. memset函数及注意事项
  8. POJ 2995 Brackets 区间DP
  9. 解决 java.security.cert.CertificateException: java.lang.IllegalArgumentException: Invalid input to toASCII:
  10. css3 伪类以及伪元素的特效