Failing to explicitly declare the visibility of a member variable could result it in having a visibility you don’t expect, and potentially leave it open to unexpected modification by other classes.

Noncompliant Code Example

class Ball {
    String color="red";  // Noncompliant
}
enum A {
  B;
  int a;
}

Compliant Solution

class Ball {
    private String color="red";  // Compliant
}
enum A {
  B;
  private int a;
}

Exceptions

Members annotated with @VisibleForTesting annotation are ignored, as it indicates that visibility has been purposely relaxed to make the code testable.

class Cone {
  @VisibleForTesting
  Logger logger; // Compliant
}

Deprecated

This rule is deprecated, and will eventually be removed.