This is impossible because of the polymorphism. Consider the following. You have the method in class A
with some access modifier which is not private
. Why not private? Because if it was private, then no other class could even know of its existence. So it has to be something else, and that something else must be accessible from somewhere.
Now let's suppose that you pass an instance of class C
to somewhere. But you upcast it to A
beforehand, and so you end up having this code somewhere:
void somewhereMethod(A instance) {
instance.method(); // Ouch! Calling a private method on class C.
}
One nice example how this got broken is QSaveFile in Qt. Unlike Java, C++ actually allows to lower access privileges. So they did just that, forbidding the close()
method. What they ended up with is a QIODevice
subclass that is not really a QIODevice
any more. If you pass a pointer to QSaveFile
to some method accepting QIODevice*
, they can still call close()
because it's public in QIODevice
. They “fixed” this by making QSaveFile::close()
(which is private) call abort()
, so if you do something like that, your program immediately crashes. Not a very nice “solution”, but there is no better one. And it's just an example of bad OO design. That's why Java doesn't allow it.
Edit
Not that I missed that your class is abstract, but I also missed the fact that B extends C
, not A
. This way what you want to do is completely impossible. If the method is public
in B, it will be public in all subclasses too. The only thing you can do is document that it shouldn't be called and maybe override it to throw UnsupportedOperationException
. But that would lead to the same problems as with QSaveFile
. Remember that users of your class may not even know that it's an instance of C
so they won't even have a chance to read its documentation.
Overall it's just a very bad idea OO-wise. Perhaps you should ask another question about the exact problem you're trying to solve with this hierarchy, and maybe you'll get some decent advises on how to do it properly.