方法覆盖(override)”的要点

方法覆盖要求子类与父类的方法一模一样,否则就是方法重载(overload)!

在子类中,若要调用父类中被覆盖的方法,可以使用super关键字。

以下子类中调用父类的代码:

public class Grandparent {
public Grandparent()
{

System.out.println("GrandParent Created.");

}
public void show()
{
System.out.println("父类的show()方法");
}

public Grandparent(String string)
{

System.out.println("GrandParent Created.String:" + string);
}

}

class Parent extends Grandparent
{

public Parent()
{
super();

System.out.println("Parent Created");
}
public void show()
{super.show();
System.out.println("子类的show()方法");
}
}

public class Test {

public static void main(String args[])
{

Parent p = new Parent();
p.show();
}
}

最新文章

  1. configure.ac:32: error: possibly undefined macro: AC_DEFINE
  2. UltraISO制作U盘启动盘安装Win7/10系统攻略
  3. ViewBag、ViewData和TempData的使用和区别
  4. 我的第一款windows phone软件
  5. Linux系统针对网卡中断的优化处理
  6. 羊和汽车问题(或s三门问题(Monty Hall problem)亦称为蒙提霍尔问题)
  7. shiro授权
  8. 7. svg学习笔记-图案和渐变
  9. k-means算法之见解(一)
  10. Codeforces Round #553 (Div. 2) D. Stas and the Queue at the Buffet 贪心+公式转化
  11. SQL优化系列——查询优化器
  12. Codeforces Round #189 (Div. 1) C - Kalila and Dimna in the Logging Industry 斜率优化dp
  13. 浅谈Kmeans聚类
  14. mysql5.6备份
  15. iOS跳转支付宝付款码和扫一扫页面
  16. C# 委托 / 跨线程访问UI / 线程间操作无效: 从不是创建控件“Form1”的线程访问它
  17. javacript总结
  18. NGUI中获取鼠标在控件内部坐标
  19. 201621123033 《Java程序设计》第10周学习总结
  20. Java泛型的应用

热门文章

  1. pyinstaller 打包多个资源文件到一个可执行文件
  2. vim快捷键及命令大全
  3. linux开机进入grub rescue界面修复
  4. 深入浅出学习透析 Nginx 服务器的基本原理和配置指南「运维操作实战篇」
  5. 【Java SE】Day05数组
  6. Java面试多线程/JUC等知识
  7. 使用Spring Reactor优化推荐流程
  8. ORM常用字段与参数(自定义字段)
  9. APP兼容测试点与WEB兼容测试点
  10. Flask初步认识