Inheritance-java
来源:互联网 发布:history.js 编辑:程序博客网 时间:2024/06/05 21:49
先看程序:
程序输出结果为:fruit;
解释如下:虽然Apple类没有name属性,但其从Fruit类继承而来,故可以访问父类对象的name属性;
也可以认为Fruit类将他的name属性传给了Apple类,即Apple类也有name属性;但是若在Apple类中添加String name;
程序输出结果为null; 所以可以更具体的解释为:
/important
子类的name的属性的值"fruit"不是通过构造函数传给子类,而是访问父类的属性值;在new()生成子类对象时,先生成父类对象,即内存存在两个对象(挨着),返回子类对象的地址,则子类对象可以访问父类的方法与属性;当在Apple类中添加String name;时,输出结果为null;
从上看来:可以认为,子类并没有生成自己的name属性,只是可以通过子类访问父类的属性;
important/
- Inheritance-java
- Java - Design with inheritance
- Java - Class Inheritance 090906
- Inheritance in Java
- java的继承 inheritance
- Inheritance
- Inheritance
- Inheritance
- Inheritance
- Java-Inheritance for Code Reuse
- Inheritance - Core Java一些问题
- Java only supports Single Inheritance, doesn’t support Multiple Inheritance
- Multiple Inheritance in Java and Composition vs Inheritance
- JAVA基础的interface与inheritance实例
- Java-Choose between Composition and Inheritance
- thinking in java(V)--composition and inheritance
- java spring Bean Definition Inheritance 继承实例
- Java Spring Tutorial -- Bean Definition Inheritance
- 2009年6月Milk Hill的麦田圈预示巨大天体将靠近详细分析
- 分布式系统部署、监控与进程管理的几重境界
- google开源的kv系统
- Android简明开发教程一:概述
- SQL Server 自动生成字符串主键 流水号
- Inheritance-java
- 教学相长
- 再谈C#委托与事件
- Constractor_this的用法
- Ajax定时刷新网页的简单实现
- DataTable转换成IList(二)
- bash 与 dash 的问题
- 关于编程的一点思考
- 解析三层架构(1)---为什么要分层?