英文:
How can I put interface in a seperate file?
问题
我被卡在这个错误上。我想把我的接口和类放在不同的文件中。但是编译器报错了。任何建议都将不胜感激。
我已经创建了一个接口和一个类。
..test\t1.java
package test;
interface t1 {
public void sayHello();
}
..\test\HelloWorld.java
package test;
public class HelloWorld implements t1 {
public void sayHello() {
System.out.println("Hello World");
}
public static void main(String args[]) {
HelloWorld h = new HelloWorld();
h.sayHello();
}
}
我尝试编译它,但是编译器报错了。
test>javac HelloWorld.java
HelloWorld.java:3: error: cannot find symbol
public class HelloWorld implements t1
^
symbol: class t1
1 error
英文:
I am stuck with this error. I want to put my interface and class in separate files. But the compiler is throwing an error. Any suggestion will be appreciated
I have create an interface and class
..test\t1.java
package test;
interface t1
{
public void sayHello();
}
..\test\HelloWorld.java
package test;
public class HelloWorld implements t1
{
public void sayHello()
{
System.out.println("Hello World");
}
public static void main(String args[])
{
HelloWorld h=new HelloWorld();
h.sayHello();
}
}
I tried to compile it but the compiler is throwing an error
test>javac HelloWorld.java
HelloWorld.java:3: error: cannot find symbol
public class HelloWorld implements t1
^
symbol: class t1
1 error
答案1
得分: 3
编译
我没有包含完整的路径
javac -classpath e:\user\java; HelloWorld.java
运行
我没有包含有效的包名和类名以执行。
E:\user\java\test>java -classpath e:\user\java\; test.HelloWorld
Hello World
英文:
For compilation
I didn't include the complete path
javac -classpath e:\user\java; HelloWorld.java
Run
I didn't include the valid package name with class name for execution.
E:\user\java\test>java -classpath e:\user\java\; test.HelloWorld
Hello World
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论