The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000

Advertisement

Advertisement

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.

Message:

Judge:No Need Public Menthods In None-Public Class

Posted by VDonkey on December 27, 2000 at 8:14 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.




Replies:

Sponsored Links



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