1.20作业
2016-01-20 20:15
218 查看
父类
子类覆盖
向上转型
package com.hanqi; public class father { public father (){ //System.out.println("父类的构造函数"); } private String x1; private String x2; public String getX1() { return x1; } public void setYuyin(String x1) { this.x1 = x1; } public String getX2() { return x2; } public void setYuhui(String x2) { this.x2 = x2; } void y1() { System.out.println("方法一"); } void y2() { System.out.println("方法二"); } }
子类覆盖
package com.hanqi; public class Son extends father { public Son() { System.out.println("子类构造函数"); } public void y2() { System.out.println("子类重写方法"); } }
向上转型
package com.hanqi; public class ceshi2 { public static void main(String[] args) { // TODO 自动生成的方法存根 Son zl = new Son(); zl.y1(); zl.y2(); father fl = new father(); fl.y1(); fl.y2(); } }
相关文章推荐
- Hibernate 的查询语句
- Quartz2.2.1开发(续)
- Quartz2.2.1开发(续)
- raspberry install python-mysqldb
- FindBugs Report安全代码检查工具问题解析
- java虚拟机运行时数据区域及对象的探秘
- BZOJ3294: [Cqoi2011]放棋子
- lr_eval_string()函数以及LR中参数、变量的简单使用
- Rescue
- iOS使用Charles(青花瓷)抓包并篡改返回数据图文详解
- 数据库系统原理(一)——数据库系统基本概念
- 【Android】1.1 开发环境安装和配置
- 置顶
- 04 WAMPServer自拟定端口
- 良心推荐,76篇前端开发技术干货,拿走,不谢~
- 模拟java死锁
- 解决.gitignore无法忽略部分文件
- Python配合BeautifulSoup读取网络图片并保存在本地
- C#中XML和json互相转换
- 03 WAMPServer多站点的配置