JAVA package存取 的作業問題

a.java程式中

加入 package A;

有一static類別方法 a(),a方法只印出字串 Hello A

package A;

public static void a()

{

System.out.println(“ Hello A ”);

}

b.java程式中呼叫 a class中的a()方法

1 Answer

Rating
  • Lv 4
    1 decade ago
    Favorite Answer

    package A;

    public class TESTA {

    public static void a(){

    System.out.println("Hello A");

    }

    }

    package B;

    import A.TESTA;//A為package TESTA為CLASS

    public class TESTB {

    public static void main(String arg[]){

    TESTA testA = new TESTA();

    testA.a();//執行TESTA裡面的a method

    }

    }

    執行結果:Hello A

    Source(s): me
Still have questions? Get your answers by asking now.