用Java导入包
如何将方法从包导入另一个程序?我不知道如何导入...我写了一个lil'代码:
How to import a method from a package into another program? I don't know how to import... I write a lil' code:
package Dan;
public class Vik
{
public void disp()
{
System.out.println("Heyya!");
}
}
然后将其保存在名为Dan的文件夹中我编译了它。生成.class文件。然后,我在下面编写了这段代码:
and then, saved it in a folder named "Dan" and I compiled it. The .class file is generated. Then, I wrote this code below:
import Dan.Vik.disp;
class Kab
{
public static void main(String args[])
{
Vik Sam = new Vik();
Sam.disp();
}
}
我把它保存在文件夹Dan之外它说:找不到符号
and I saved it outside the folder "Dan" and it says : "cannot find symbol"
我将第一个代码保存在C:\ Dan \ Vik.java
中,第二个代码保存在C:\\ \\ kab.java
I saved the first code in C:\Dan\Vik.java and the second in C:\Kab.java
你不用Java导入方法,只有类型:
You don't import methods in Java, only types:
import Dan.Vik;
class Kab
{
public static void main(String args[])
{
Vik Sam = new Vik();
Sam.disp();
}
}
例外是所谓的静态导入,它允许您从其他类型导入类( static
)方法。
The exception is so-called "static imports", which let you import class (static
) methods from other types.