首页 > 代码库 > wolf
wolf
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。