title: How do I access a setter from two levels up using abstraction + inheritance in Java?
body: <blockquote>
  <p>Let's say I have a:</p>
  </blockquote>
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  public Abstract class A {
  private static List&lt;Object&gt; list = new ArrayList&lt;Object&gt;();
  public List&lt;Object&gt; getList() {
      return menu;
  }
  
  public void setList(List&lt;Object&gt; list) {
      A.List = list;
  }
  }
  
  public abstract class C extends A {
  @Override
  public List&lt;Object&gt; getList() {
      return list;
  }
  @Override
  public void setList(List&lt;Object&gt; list) {
      A.list = list;
  }
  }
  
  Public abstract class B extends A {
  
  // there are some overridden methods which have nothing to do with the 
  // list I am having issue with
  
  }
  
  public class E extends C{
  static {
         A.menu.add(&quot;addItem&quot;);
       }    
  B(int num) {
  super.num = num;
  }
  
  // some more codes
  }
  </code></pre>
  <blockquote>
  <p>// finally, here is the base class</p>
  </blockquote>
  <pre><code>   public class BaseClass extends C {
     Public static void main(String[] args){
     //  C.method1(); // assume there is no problem, it rans
     //  C.method2(); // same above
     //  C.method3(); // same above, runs no problem
  
      }
  }
  </code></pre>
  <blockquote>
  <p>****************  Misc info &amp; my questions **************
  a) class A, B, C are abstract classes
  b) class D, E, BaseClass are concrete classes</p>
  <p>also currently&gt;</p>
  </blockquote>
  <blockquote>
  <p>[A &gt; B &gt; D &amp;&amp; A &gt; C &gt; E &amp;&amp; BaseClass] ( '&gt;' means 'extends' )</p>
  </blockquote>
  <blockquote>
  <p>c) if I comment out static block in class B, all codes run without any
  issue; if I don't comment out, I get &quot;UnsupportedOperationException&quot;
  exception.</p>
  </blockquote>
  <blockquote>
  <p>d) if I use [try catch] clock to catch the exception of the static code, then I &gt; get the same exception, but at least the code runs (this may seems a dumb
  comment to professional programmers; but just wanted to provide as much
  details as possible)</p>
  </blockquote>
  <blockquote>
  <p>e) originally there was</p>
  </blockquote>
  <pre><code>static {
      menu.add(&quot;newItem&quot;);
  }
  </code></pre>
  <blockquote>
  <p>now I added [try  catch] to see what's happening; and one more</p>
  </blockquote>
  <pre><code>System.out.println(&quot;static block is called&quot;);
  </code></pre>
  <blockquote>
  <p>in the [catch] block added some statements to check if it's catching, it
  prints, but seems to be not adding the item.</p>
  </blockquote>
  <blockquote>
  <p>In class <code>[BaseClass]</code> I created two objects of D, and two objects of class
  E; static block is inside the E to add one more item to the list.</p>
  </blockquote>
  <blockquote>
  <p>again if I comment out [the object and it's implementation of Class E]
  inside BaseClass, everything runs smooth.</p>
  </blockquote>
  <blockquote>
  <p>if I comment out [the object and method implementation of class D] in class
  BaseClass, code seems to be running</p>
  </blockquote>
  <blockquote>
  <p>my only question, how can I make this static block work and add the item to
  the list defined in abstract super class A from </p>
  </blockquote>
  <blockquote>
  <p>if said too much, and confused you, please check the picture I attached.</p>
  </blockquote>
  <blockquote>
  <p>Thank you in advance.</p>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/8wCnr.png" rel="nofollow noreferrer">enter image description here</a></p>