== Why is this an issue?

Shadowing parent class ``++static++`` methods by creating methods in child classes with the same signatures can result in seemingly strange behavior if an instance of the child class is cast to the parent class and the static method is invoked using a reference to the child class.  In such cases, the parent class' code will be executed instead of the code in the child class, confusing callers and potentially causing hard-to-find bugs. Instead the child class method should be renamed.

=== Noncompliant code example

[source,java]
----
public class Fruit {
  public static Double getCost() {
    return 3.5;
  } 
}

public class Raspberry extends Fruit {
  public static Double GetCost()  // Noncompliant { 
    return 7.5;
  }
}

// ...
var r = new Raspberry();
var f = (Fruit) r;
System.out.println(r.GetCost());  // prints 7.5
System.out.println(f.GetCost());  // prints 3.5; there's only one instance but different code executes depending on cast
----

=== Compliant solution

[source,java]
----
public class Fruit {
  public static DoubleGetCost() {
    return 3.5;
  } 
}

public class Raspberry extends Fruit {
  public static Double GetInflatedCost() { 
    return 7.5;
  }
}

// ...
var r = new Raspberry();
var f = (Fruit) r;
System.out.println(r.GetCost());  // prints 3.5, Raspberry.GetCost() would be even better
System.out.println(f.GetCost());  // prints 3.5; same code executes every time
System.out.println(r.GetInflatedCost()); // prints 7.5, Raspberry.GetInflatedCost() would be even better
----

=== Exceptions

This rule ignores ``++private++`` parent class members.

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

include::../message.adoc[]

include::../highlighting.adoc[]

'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]

endif::env-github,rspecator-view[]
