As for my understanding:
When a method is static it is
- early bind
- can call with the name of class even before no object is created
- can call only static member inside it.
I never found any other behaviour of static either at compile time or runtime. Is there any?
When a method is private it is
- also early bind
- can only call inside call so can call directly without object.
For example the hugeCapacity()
method in the ArrayList
class.
private static final int DEFAULT_CAPACITY = 10;
private static int hugeCapacity(int minCapacity) {
if (minCapacity < 0) // overflow
throw new OutOfMemoryError();
return (minCapacity > MAX_ARRAY_SIZE) ?
Integer.MAX_VALUE :
MAX_ARRAY_SIZE;
}
Since there are in Java private+static method exist. Why their need occurs. Is it for restriction purpose, to restrict access of non static variables inside a method?