Sorry the question wasn't properly stated by me earlier. I try to implent the Factory Pattern. A better example: It is an abstract class Human with a function create. Based on the arguments that is passed to create it decides whether to return an instance of its subclass Man or an instance of subclass Woman. So you call create with:
Human john = Human.create("Man");
The subclasses Man and Woman are inherited from the abstract class Human and are defined in the same file as Human. I don't want it to be possible to extend it by: Human lisa = new Human("woman") {};
From the main program. Thanks!
EDIT:
Thanks for all the help! The solution I finally used was to let the class Human be public, as well as its function create. The Human constructor and the Man and Woman classes are declared "package-protected".