本帖最后由 ameanboy 于 2016-3-18 22:50 编辑
- public class Dervied extends Base {
- private String name = "dervied";
- public Dervied() {
- tellName();
- printName();
- }
-
- public void tellName() {
- System.out.println("Dervied tell name: " + name);
- }
-
- public void printName() {
- System.out.println("Dervied print name: " + name);
- }
- public static void main(String[] args){
-
- new Dervied();
- }
- }
- class Base {
-
- private String name = "base";
- public Base() {
- tellName();
- printName();
- }
-
- public void tellName() {
- System.out.println("Base tell name: " + name);
- }
-
- public void printName() {
- System.out.println("Base print name: " + name);
- }
- }
复制代码
输出结果是:
- Dervied tell name: null
- Dervied print name: null
- Dervied tell name: dervied
- Dervied print name: dervied
复制代码 为什么呢。。name不是已经被初始化赋值了吗。。
还是理解不能 我滚回去重学面向对象的基础概念了
|
|