我认为不可能。但是,您可以通过从其规范中 删除Rotate()* 方法来进一步优化 Shape 类,而定义另一个名为
RotatableShape 的Shape 子类 ,并让 Circle 从 Shape 派生 ,并从
RotatableShape 派生 所有其他 Rotatable类 。 ***
例如:
public class Shape{ //all the generic methods except rotate()}public class RotatableShape extends Shape{ public void rotate(){ //Some Code here... }}public class Circle extends Shape{ //Your implementation specific to Circle}public class Rectangle extends RotatableShape{ //Your implementation specific to Rectangle}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)