tags:

views:

99

answers:

2

as for my observation when the class itself is having default access modifier, what is the use of having public methods in it. the java compiler could have stopped using public methods in default class. is there any reason for that?

+5  A: 

One reason: if your class implements some interface (or extends some abstract class with abstract public methods), then you may not reduce the visibility of those implemented methods.

Jonathan Feinberg
Also public subclasses will inherit the methods as public.
Tom Hawtin - tackline
+4  A: 

The non-public class might implement a public interface. This would mean that classes outside of the package could not create an instance of this class or create references of that type, but they would still be able to invoke methods on it if passed an instance.

For example, a public factory class might create an instance of an non-public class in its package and return it.

Dan Dyer
Even a non-public interface has public methods.
Tom Hawtin - tackline