code: public static Method getAccessibleMethodFrom (
          Class<?> clazz, String methodName, Class<?>[] parameterTypes)
      {
          // Look for overridden method in the superclass.
          Class<?> superclass = clazz.getSuperclass();
          Method overriddenMethod = null;
  
          if (superclass != null && classIsAccessible(superclass)) {
              try {
                  overriddenMethod = superclass.getMethod(methodName, parameterTypes);
              } catch (NoSuchMethodException nsme) {
                  // no problem
              }
  
              if (overriddenMethod != null) {
                  return overriddenMethod;
              }
          }
  
          // If here, then clazz represents Object, or an interface, or the superclass did not have
          // an override.  Check implemented interfaces.
          Class<?>[] interfaces = clazz.getInterfaces();
          for (int i = 0; i < interfaces.length; ++i) {
              if (classIsAccessible(interfaces[i])) {
                  try {
                      overriddenMethod = interfaces[i].getMethod(methodName, parameterTypes);
                  } catch (NoSuchMethodException nsme) {
                      // no problem
                  }
                  if (overriddenMethod != null) {
                      return overriddenMethod;
                  }
              }
          }
  
          // Try superclass's superclass and implemented interfaces.
          if (superclass != null) {
              overriddenMethod = getAccessibleMethodFrom(superclass, methodName, parameterTypes);
              if (overriddenMethod != null) {
                  return overriddenMethod;
              }
          }
  
          // Try implemented interfaces' extended interfaces...
          for (int i = 0; i < interfaces.length; ++i) {
              overriddenMethod = getAccessibleMethodFrom(interfaces[i], methodName, parameterTypes);
              if (overriddenMethod != null) {
                  return overriddenMethod;
              }
          }
  
          // Give up.
          return null;
      }
docs: Searches for the method with the given name and formal parameter types that is in the
  nearest accessible class in the class hierarchy, starting with clazz's superclass. The
  superclass and implemented interfaces of clazz are searched, then their superclasses,
  etc. until a method is found. Returns null if there is no such method.
  
  @param clazz a class.
  @param methodName name of a method.
  @param parameterTypes Class array representing the types of a method's formal parameters.
  
  @return the nearest method located, or null if there is no such method.