静态方法调用成员

问题描述:

import lotus.domino.*;

public class JavaAgent extends AgentBase{
    //public void NotesMain() {
 public static void main(String[] args) {
       try {
        
             hello();
           
       } catch (Exception e) {
          e.printStackTrace();
       }
    }
 
  public  void hello(){
   System.out.println("test");
  }

 

}

处理办法:把此方法作为内部类的方法来访问。外部类按常规的类访问方式使用内部类,唯一的差别是外部类可以访问内部类的所有方法与属性,包括私有方法与属性。

至于内部类对外部类的使用,我在最前面就说了:内部类可以访问外部类的所有方法与属性,但static的内部类只能访问外部类的静态属性与方法。

import lotus.domino.*;

public class JavaAgent extends AgentBase{
    //public void NotesMain() {
 public static void main(String[] args) {
       try {
        
              System.out.println("Document created and saved");
              JavaAgent outer = new JavaAgent();
              LaLa o = outer.new LaLa();
              o.hello();
           
       } catch (Exception e) {
          e.printStackTrace();
       }
    }
 public class LaLa{
  public  void hello(){
   System.out.println("test");
  }
 }
}

你可能感兴趣的:(Lotus)