Suppose I have class/interface A
that is extended/implemented
by class B
and class C
. Class/interface A
contains method X
. Is there a way to have method X
without a body (X();
) and so it must be implemented by class B
and class C
, but not give class B
and class C
(or any other class except possibly class/interface A
) access to each other's method X
?
? class/interface A {
? X();
}
? class B extends/implements class/interface A {
@Override
? X() {
...code...
}
}
? class C extends/implements class/interface A {
@Override
? X() {
...code...
}
}
I am not sure of modifiers, represented with question marks above, and I am not sure if A should be a class or interface.
EDIT:
Additionally, instances of classes B and C are created in class D
. The instance of class C
in class D
is constructed with the instance of class B
in class D
as a parameter, which is set as a class variable which this instance of class C
is constantly getting data from. I do not want this instance of class C
to be able to call its class variable object B
's method X
.