+1 Unresolved compilation problems:没有编译!is undefined for the type 没找到类型
为啥没有编译啊?有什么错吗?Animal animal = new Tiger();具体怎么使用,还是报错啊? Exception in thread "main" java.lang.Error: Unresolved compilation problems: Animal cannot be resolved to a type tiger cannot be resolved tiger cannot be resolved tiger cannot be resolved at test.main(test.java:5)
怎么会有人说测试过了 public class Tiger implements Animal { public void sleep(){ System.out.println("the tiger sleep"); } public void eat(){ System.out.println("the tiger eat"); } public void breath(){ System.out.println("the tiger breath"); } } 这些方法都没括号
这样new实现类,接口就没用了,接口已经实现了,直接调用接口就可以了。
各位,已经加上括号了,但是还是出现问题。 Exception in thread "main" java.lang.Error: Unresolved compilation problem: Animal cannot be resolved to a type at Tiger.<init>(Tiger.java:2) at test.main(test.java:4)
+1 Unresolved compilation problems:没有编译!is undefined for the type 没找到类型
为啥没有编译啊?有什么错吗?Animal animal = new Tiger();具体怎么使用,还是报错啊?
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Animal cannot be resolved to a type
tiger cannot be resolved
tiger cannot be resolved
tiger cannot be resolved at test.main(test.java:5)
lz你这问题我真是无力吐槽了
你仔细看看你tiger类的方法,都没有写小括号!!!
楼上都什么眼神楼主,我也是无力吐槽了
你仔细看看你的tiger类里的方法,都没有写小括号!!!其他都是正确的,实验过了。
public class Tiger implements Animal {
public void sleep(){ System.out.println("the tiger sleep"); }
public void eat(){ System.out.println("the tiger eat"); }
public void breath(){ System.out.println("the tiger breath"); } }
这些方法都没括号
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Animal cannot be resolved to a type at Tiger.<init>(Tiger.java:2)
at test.main(test.java:4)
和一楼说的没关系的,就算你写成Tiger tiger=new Tiger();也没问题,对的。把你接口的方法前加上public。
接口中的方法默认被定义为public吧,不需要显示添加。问题在于,Animal.java是Interface,现在新建个Class,把Animal.java的内容拷贝进去就运行成功了。不知道为什么?
大哥,java默认的作用域自古以来就是friendly,从来没有默认为public的说法你重新建的接口是不是放在和tiger.java一个包内了?因为friendly的作用域是同一个包中。能理解不。
你重新建的接口是不是放在和tiger.java一个包内了?因为friendly的作用域是同一个包中。能理解不。 ]
我建的接口Interface是和tiger.java在一个包内啊。既然friendly的作用域是同一个包中,我新建的接口Interface Animal.java,实现类Tiger.java,还有测试类Test.java都在同一个包中,为什么运行失败呢?而我新建一个Class,把接口Animal.java的内容拷进去就能运行成功呢?我还是不理解,抱歉。