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