If a class access specfier is default i.e if the class is visible only in the package, then why are the members allowed to have public as access specifier, any way the class will not be available in other packages.so,the members even though public will be visible only in that package
When the class is not visible, then none of its members are visible. But we have the member methods to be public because mostly all the classes implement interfaces and we are forced to have the methods to be public.
Further in future when the class is made visible outside we need not change the API.
According to <<The Java Language Specification>> 22.214.171.124, if a class has a public superclass or superinterface, with the help of another public class in the same package that returns an instance of this class, instance of the class might be available at run time to codes outside its package, and its public methods, which implement or override the methods of its public superclass or superinterface, can be invoked through these instances.
Get off me! Here, read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop