現實多重繼承

話不多說,之間上代碼:

interface Father {
	public int strong();
}

interface Mother {
	public int kind();
}

class FatherImpl implements Father {
	public int strong() {
		return 8;
	}
}

class MotherImpl implements Mother {
	public int kind() {
		return 8;
	}
}

class Son extends FatherImpl implements Mother {
	public int strong() {
		return super.strong() + 1;
	}

	public int kind() {
		return new MotherSpecial().kind();
	}

	private class MotherSpecial extends MotherImpl {
		public int kind() {
			return super.kind() - 1;
		}
	}
}

class Daughter extends MotherImpl implements Father {

	public int strong() {
		return new FatherImpl() {
			public int strong() {
				return super.strong() - 2;
			};
		}.strong();
	}
}

選自:《編寫高質量代碼 改善Java程序的151個建議》
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章