[Solved] Directly access methods from another Class


Firstly, your example doesn’t compile because you cannot name your package “package”. “package” is a Java keyword and not allowed to use as an identifier.

So we call it “mypackage”. And according to Java conventions you should name classes with first letter uppercase. So I will use Dialog instead of dialog for the class name in my example below.

Then you can use a static import to call the method dialog() without prefix.

import static mypackage.Dialog.*;

public class Class1 {
  public static void main(String[] args) {
    dialog("This is dialog");
  }
}

solved Directly access methods from another Class