如何在JAVA中的静态类中访问私有内部类的私有参数化方法



如何从main方法访问Inner类的getMeSomething方法?我所需要的只是能够发送一个整数并在main方法中获得返回值。

public class OuterClass {
   public static void main(String[] args) {
    //Using Java Reflection...I tried to create an inner class Object
    //created a outer class object
    //and invoke the method without any success
   }
  static class Inner {
     private class Private {
        private int getMeSomething(int num) {
            return (num*2);
        }
     }
  }//end of inner class
} //end of outer class

您需要一个Inner和Private:的实例

      public static void main(String[] args) {
        //Using Java Reflection...I tried to create an inner class Object
        //created a outer class object
        //and invoke the method without any success
               Private p = new Inner ().new Private ();
           System.out.println(""+p.getMeSomething(21));
       }

相关内容

  • 没有找到相关文章

最新更新