You can solve your problem by using different packages for your classes:
Put your class containing the main() method into package m. Then put class A in package a and make it public. Put class B in package ba, too and make it only package protected (skip the public key word).
Now you can access class A from your main(), but you can't access class B.