The only thing even slightly close (though not really) could be achieved using the protected modifier. If all classes in A and B are protected, and classes in C extend those.... But then again, nothing would stop classes from packaged D from extending classes from packages A and B as well.