The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Public Methods in Non Public classes

Posted by M Nelson on January 16, 2001 at 4:00 PM

> I think that
> if one class was not public, all methods of it need not to be public, (at least on most occasions).
> for:
> if another class in the same package who want to use methods in the class, it will work without modifier(or to say with default 'friendly'),
> on the other hand, if another class not in the same package who want to use methods in the class, it will be impossible for he can't even access the class, not to mention the methods.

> But there are too many examples showing public methods defined in none-public classes. I am confused.
> eg:
> class Cleanser{
> private String s = new String("Cleanser");
> public void append(String a){s+=a;}
> public void dilute(){append(" dilute()");}
> public void ...
> ...
> (quoted from "Thinking in java Chapter Six 6.2")
> Help me, please. Thank you.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us