使用来自另一个“class interface”或“enum expected”的一个包时出错 [英] Error using one package from another "class interface or enum expected"
本文介绍了使用来自另一个“class interface”或“enum expected”的一个包时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
package students;
import java.util.*;
public class p1 {
private int n1 = 2;
int n2 = 3;
protected int n3 = 5;
public int n4 = 7;
}
package students1;
class abc extends students.p1 {
public static void main( String args[]) {
abc obj = new abc();
System.out.println(obj.n4);
System.out.println(obj.n3);
}
}
这是我的代码,但它给出了一个错误类接口或者在包语句中预期的枚举
This is my code but its giving an error class interface or enum expected at the package statements
推荐答案
这些必须在单独的文件中。一个名为p1.java,另一个名为abc.java, abc
应为公共类。
These must be in separate files. One named p1.java, the other named abc.java, and abc
should be a public class.
As注意,最好用大写字母开始你的类型名称,所以你应该有两个类: P1.java
和 Abc。 java
,而不是 p1.java
和 abc.java
。
As a side note, it is good practice to start your type names with a capital letter, so you should have two classes: P1.java
and Abc.java
, instead of p1.java
and abc.java
.
这篇关于使用来自另一个“class interface”或“enum expected”的一个包时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文