Java 面向对象 之 super 关键字
http://www.verejava.com/?id=17159596599630
/** this: 代表当前类的引用 1. 当局部变量和成员变量同名时, 成员变量要加 this 限定 2. 实例化时 可以用 this 调用当前类的构造方法, 必须写在第一行 3. 可以用 this 调用当前类的 普通方法 super : 代表当前父类的引用 1. 实例化子类时, 可以用 super 调用父类的 非私有方法 2. 实例化子类时. 可以用 super 调用父类的 构造方法 , 必须写在第一行 3. 在子类的方法中 , 可以用 supe 调用父类的 非私有方法. */ public class Test1 { public static void main(String[] args) { // 实例化 农夫 Father father = new Father(); father.setName("农夫"); father.setAge(90); System.out.println(father.getAge() + " 岁 " + father.getName() + " 有 " + father.getWealth()); Father father = new Father("农夫", 90); System.out.println(father.getAge() + " 岁 " + father.getName() + " 有 " + father.getWealth()); Son son = new Son("农夫", 90); System.out.println("儿子知道父亲的 : " + son.getAge() + " 岁 " + son.getName() + " 有 " + son.getWealth()); son.work(); } } //父类 class Father { private String name; private int age; private String wealth; public Father() { wealth = "100两黄金"; } public Father(String name, int age) { this(); this.name = name; //this.age=age; this.setAge(90); } public void work() { System.out.println("耕地"); } public String getWealth() { return wealth; } public void setAge(int age) { this.age = age; } public int getAge() { return age; } public void setName(String name) { this.name = name; } public String getName() { return name; } } //子类 class Son extends Father { public Son(String name, int age) { super(name, age); //super.setName(name); //super.setAge(age); } public void work() { super.work(); System.out.println("儿子 寻找黄金宝藏"); System.out.println("只有通过自己的勤奋劳动, 才能得到果实 是最大的宝藏"); } }
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
新书上架:《Spring Boot 开发实战》基于 Kotlin + Gradle + Spring Boot 2.0 的企业级服务端开发实...
新书上架:《Spring Boot 开发实战》 — 基于 Kotlin + Gradle + Spring Boot 2.0 的企业级服务端开发实战 京东下单链接 https://item.jd.com/31178320122.html 天猫下单链接 https://detail.tmall.com/item.htm?id=574928877711 基本信息 作者:陈光剑 丛书名:华章程序员书库 出版社:机械工业出版社 ISBN:9787111603337 上架时间:2018-8-4 出版日期:2018 年8月 开本:16开 页码:375 版次:1-1 所属分类: [计算机](http://product.china-pub.com/cache/browse2/59/1_1_59_0.html)>[软件与程序设计](http://product.china-pub.com/cache/browse2/59/1_1_59-05_0.html)>[JAVA(J#)](http://product.china-pub.com/cache/browse2/59/1_1_59-05-...
- 下一篇
C# 设置Excel条件格式(二)
上一篇文章中介绍了关于设置Excel条件格式,包括基于单元格值、自定义公式等应用条件格式、应用数据条条件类型格式、删除条件格式等内容。在本篇文章中将继续介绍C# 设置条件格式的方法。 要点概述: 1. 应用条件格式用于高亮重复、唯一数值 2. 应用条件格式用于高亮峰值(最高、最低) 3. 应用条件格式用于高亮低于、高于平均值的数值 使用工具: Spire.XLS for .NET 注:在编辑代码时注意在程序中添加引用Spire.Xls.dll,dll文件可在安装路径下的Bin文件夹中获取。 C#代码示例(供参考) 【示例 1】应用条件格式用于高亮重复、唯一数值 C# using Spire.Xls; using System.Drawing; namespace HightDuplicateData_XLS { class Program { static void Main(string[] args) { //实例化Workbook类,加载测试文档 Workbook workbook = new Workbook(); workbook.LoadFromFile("test.xl...
相关文章
文章评论
共有0条评论来说两句吧...