重复Disabling inherited method on derived class
这是我的班级代码:
class Parent{
public bool sum(int a){return true;}
public int mul(int a){return a*a;}
}
以及另外两个扩展父类的类:
class derived extend parent{
//here this child can see two methods of parent class and
//I want just see sum method in here and don't see mul method
}
class derivedb extend parent{
//here this child can see two methods of parent class and
//I want here just see mul method.
}
答案 0 :(得分:2)
您可以通过在父类中将mul
作为私有方法来实现。因此,mul方法仅在Parent
类
class Parent{
public bool sum(int a){return true;}
private int mul(int a){return a*a;}
}