public interface Father {
public int strong();
}
interface Mother {
public int kind();
}
class FatherImpl implements Father {
// 父亲的强壮指数为8
@Override
public int strong() {
return 8;
}
}
class MotherImpl implements Mother {
// 母亲的温柔指数为8
@Override
public int kind() {
return 8;
}
}
class Son extends FatherImpl implements Mother {
@Override
public int strong() {
// 儿子比父亲强壮
return super.strong() + 1;
}
@Override
public int kind() {
return new MotherSpecial().kind();
}
private class MotherSpecial extends MotherImpl {
@Override
public int kind() {
// 儿子的温柔指数降低了
return super.kind() - 1;
}
}
}
class Daughter extends MotherImpl implements Father {
@Override
public int strong() {
return new FatherImpl() {
@Override
public int strong() {
//女儿的强壮指数降低了
return super.strong() - 2;
}
}.strong();
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |