ITeye博客

网易2014年校招杭州站的一道题目

lxtc2014 · 2013-10-18 22:08 · 编程语言 · Markdown

记下来只为给自己一个教训:


class Base{
	private String name = "base";
	public Base() {
		tellName();
		printName(name);
	}
	
	public void tellName(){
		System.out.println("Base tell: "+name);
	}
	
	public void printName(String name){
		System.out.println("Base print: "+name);
	}
	
}
public class Derived extends Base{
	private String name = "derived";
	
	public Derived() {
		tellName();
		printName(name);
	}
	
	public void tellName(){
		System.out.println("Derived tell: "+name);
	}
	
	public void printName(String name){
		System.out.println("Derived print: "+name);
	}
	public static void main(String[] args) {
		new Derived();
	}
}

输出: Derived tell: null Derived print: base Derived tell: derived Derived print: derived

评论(1)

  1. #1 楼 · oyp2009 · 2013-10-24 17:52

    一个人都没有啊!

评论功能维护中,当前仅展示历史评论。