include::../why.adoc[]

[source,java,diff-id=1,diff-type=noncompliant]
----
class Outer
{
  public static int A;

  public class Inner
  {
    public int A; // Noncompliant
    public int MyProp
    {
      get { return A; } // Returns inner A. Was that intended?
    }
  }
}
----

Here's an example of compliant code after renaming the inner class member, this way the property will return the `Outer` A:

[source,java,diff-id=1,diff-type=compliant]
----
class Outer
{
  public static int A; // Compliant

  public class Inner
  {
    public int B;
    public int MyProp
    {
      get { return A; } // Returns inner A
    }
  }
}
----

Or if you want to reference the `Inner` A field:

[source,java]
----
class Outer
{
  public static int B;

  public class Inner
  {
    public int A; // Compliant
    public int MyProp
    {
      get { return A; } // Returns inner A
    }
  }
}
----

== Resources

=== Documentation

* https://wiki.sei.cmu.edu/confluence/x/5DVGBQ[CERT, DCL51-J.] - Do not shadow or obscure identifiers in subscopes
* https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html[Nested and Inner classes]

include::../rspecator.adoc[]