The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
May 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:

Private method access

Posted by Jamshed on May 17, 2000 at 7:04 AM


In the following code, a private member function (getNumInstances) is being called by the class's
client. I thought private member functions are
only accessible to class's member functions and
not the external world. Please explain.


public class CountInstances {
private static int numInstances = 0 ;

private int getNumInstances() {
return numInstances;
}

private static void addInstance() {
numInstances++;
}

CountInstances() {
CountInstances.addInstance();
}

public static void main(String args[]) {

CountInstances ref = new CountInstances();
System.out.println("Starting with " + ref.getNumInstances() + " Instances");

}
}





Replies:

Sponsored Links



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