抽象基类是否有可能拥有只有某些派生类才能访问某些抽象方法的抽象方法?我正在尝试做的是限制能够从不同的继承类调用的可能方法。这是我的问题的一个例子:
public abstract Foo
{
...
public abstract void fooMethod1(int num1);
public abstract void fooMethod2(int num2);
}
public Bar1 extends Foo // This class shouldn't be able to access fooMethod2()
{
...
@Override
public void fooMethod1(int num1)
{
System.out.println((num1 * 5));
}
}
public Bar2 extends Foo // This class has no restrictions
{
...
@Override
public void fooMethod1(int num1)
{
System.out.println((num1 * 10));
}
@Override
public void fooMethod2(int num2)
{
System.out.println((num2 * 5));
}