# \[Java\] Indirect access to static member

**URL:** <https://community.sonarsource.com/t/java-indirect-access-to-static-member/3530>\
**Category:** New rules / language support\
**Tags:** java\
**Created:** [October 19, 2018, 5:09pm UTC](https://community.sonarsource.com/t/java-indirect-access-to-static-member/3530 "2018-10-19T17:09:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thw](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/thw/32/16105_2.png) [@thw](https://community.sonarsource.com/u/thw)\
**Post date:** [October 19, 2018, 5:09pm UTC](https://community.sonarsource.com/t/java-indirect-access-to-static-member/3530/1 "2018-10-19T17:09:09Z")

</div>

**Description**  
Static members should not be accessed via derived classes. It is confusing and may lead to different behavior if another static member with the same signature is added to the derived class.

**Type**  
Code Smell

**Snippet**

```
public class IndirectAccessToStaticMember {

	public static class Base {
		public static String method() {
			return "hello world";
		}
	}
	
	public static class Derived extends Base {
		
	}
	
	public static void main(String[] args) {
		System.out.println(Derived.method()); // Noncompliant
		System.out.println(Base.method()); // Compliant
	}
	
}

```

**Note**  
Also covered by Eclipse JDT.

---

<div class="post-metadata">

**Author:** ![Lena](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/lena/32/66719_2.png) [@Lena](https://community.sonarsource.com/u/Lena)\
**Post date:** [July 4, 2019, 2:21pm UTC](https://community.sonarsource.com/t/java-indirect-access-to-static-member/3530/3 "2019-07-04T14:21:54Z")

</div>

Hi,

Good idea, [ticket](https://jira.sonarsource.com/browse/SONARJAVA-3137) is created.
