首页 > 其他 > 详细

wolf

时间:2017-04-07 18:06:24      阅读:173      评论:0      收藏:0      [点我收藏+]
package com.wh.Demo50;

/**
 * @author 王恒
 * @datetime 2017年4月7日 下午4:40:54
 * @description
 * 分析:子类重写父类的方法时,调用子类的构造方法
 *     这是一道逻辑题,比较绕,不知道程序怎么走的时候,用debug模式,追踪走一边,所有方法均打断点
 */
public class Demo04_wolf {
	public static void main(String[] args) {
		Wolf w = new Wolf("灰太狼", 32.3);
		System.out.println(w);
	}
}

class Animal {

	private String desc;

	public Animal() {
		this.desc = getDesc();
	}

	public String getDesc() {
		return "Animal";
	}

	public String toString() {
		return desc;
	}
}

class Wolf extends Animal {
	private String name;
	private double weight;

	public Wolf(String name, double weight) {
		// super();
		this.name = name;
		this.weight = weight;
	}

	public String getDesc() {
		return "Wolf[name=" + name + ", weight=" + weight + "]";
	}
 
}

  运行结果:

      Wolf[name=null, weight=0.0]

wolf

原文:http://www.cnblogs.com/1020182600HENG/p/6679347.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!