title: call anonymous class method in java
body: <p>I am trying to write code for the following question :
  WAP to get empno ,DOB and salary of few employees.
  Write two anonymous inner class , one that implements an interface to sort the employees as per their DOB and another anonymous inner class that extends a class to sort the employees as per their salary .
  My code is :</p>
  
  <pre><code> //required import statements
  
  public class OuterClass {
      private int empno;
      private String DOB;
      private int salary;
  
      public OuterClass() {
          // TODO Auto-generated constructor stub
      }
  
      public OuterClass(int empn, String dob, int sal) {
          //code for paramaterized constructor
      }
  
      public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          List&lt;OuterClass&gt; list = new ArrayList&lt;OuterClass&gt;();
          while (true) {
              //code for input from user and adding it in list
          }   
      }
  
      Employee abc = new Employee() {
          @Override
          void SalarySort(List&lt;OuterClass&gt; l) {
              Collections.sort(l, new Comparator&lt;OuterClass&gt;() {
                  public int compare(OuterClass e1, OuterClass e2) {
                      return e1.salary - e2.salary;
                  }
              });
              Iterator&lt;OuterClass&gt; itr = l.iterator();
              while (itr.hasNext()) {
                  OuterClass employee = (OuterClass) itr.next();
                  System.out.println("Emp no : " + employee.empno + " Emp dob : "
                          + employee.DOB + " Emp Salary : " + employee.salary);
              }
          }
  
      }.SalarySort(list);// compile error : create local field list
  
  }
  
  class Employee {
      void SalarySort(List&lt;OuterClass&gt; l) {
  
      }
  }
  </code></pre>
  
  <p>My question is,I cant call the anonymous class Employee's method SalarySort,how to solve the problem?</p>