Question

I know what the difference between private, public and protected. but I don't know what the difference between private field and filed without any access modifiers.

class Example{
private int field1;
int field2;
}
Was it helpful?

Solution

In Java if you leave the access specifier off then the member is "package" level. Package level members can be seen by the class that defines the member and other classes in the same package. The difference between that and private are private members may only be seen by the class which defines it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top