我的程序如下:
interface Act{
void act();
}
class Actor1 implements Act{
public void act(){
System.out.println("To be,or not to be");
}
}
class Actor2 implements Act{
public void act(){
System.out.println("Wherefore art thou Romeo?");
}
}
public class TryOut{
public static void main(String []args){
Actor1 hamlet=new Actor1();
Actor2 juliet=new Actor2();
tryout(hamlet);
tryout(juliet);
}
private static void tryout(Act actor){
actor.act();
}
}
我没有设classpath,只设了path运行其他的程序没问题,只运行这个程序有问题
运行时提示:
error:connot read TryOut.java
还有最后一个方法是什么意思,它有什么作用?
interface Act{
void act();
}
class Actor1 implements Act{
public void act(){
System.out.println("To be,or not to be");
}
}
class Actor2 implements Act{
public void act(){
System.out.println("Wherefore art thou Romeo?");
}
}
public class TryOut{
public static void main(String []args){
Actor1 hamlet=new Actor1();
Actor2 juliet=new Actor2();
tryout(hamlet);
tryout(juliet);
}
private static void tryout(Act actor){
actor.act();
}
}
我没有设classpath,只设了path运行其他的程序没问题,只运行这个程序有问题
运行时提示:
error:connot read TryOut.java
还有最后一个方法是什么意思,它有什么作用?
最后一个方法是写了一个静态方法,参数对象型,是用的接口Act,因为类Actor1和Actor2分别实现了这个接口,而且里面都有act()方法,所以运行结果就是分别打印出的那两句话。
提示的错误是没有找到TryOut.java文件,即编译没通过,与path有关,在path中添加.路径,然后把dos命令窗口切换到TryOut.java所在的路径再进行编译
我用得还不如jdk简直就是垃圾!