[英]If i compile any java program, i got this error
If i compile any java program, I got this error 如果我编译任何java程序,我收到此错误
b1.java:3: cannot access String
bad class file: .\String.java
file does not contain class String
Please remove or make sure it appears in the correct subdirectory of the classpath.
public static void main(String ar[])throws IOException{
As visible from your compilation step in the terminal, 从终端的编译步骤可以看出,
String is already a Java-library class available in JDK.
Hence,you can't give such name to your program/class. 因此,您不能将此名称赋予您的程序/类。
Hence,you receive such error. 因此,您收到此类错误。
Try naming it something else like public class MyString
and rename your source code as MyString.java
---recompile it and then you won't receive such errors. 尝试将其命名为
public class MyString
,并将源代码重命名为MyString.java
---重新编译它,然后您将不会收到此类错误。
String is a datatype defined within the Java-Library. String是Java-Library中定义的数据类型。 You cannot name a variable as String or any other name of datatypes, in that way you cannot name it for a class.
您不能将变量命名为String或任何其他数据类型名称,这样您就无法为类命名。
String is in-built Class in Java. String是Java中的内置类。 Hence you can not give the name for Class as String.
因此,您不能将Class的名称赋予String。 you can check it by - just give the name for Class as
Class string
and save it as string.java
. 你可以检查它 - 只需给Class作为
Class string
的名称,并将其保存为string.java
。 now it will compile and run properly. 现在它将编译并正常运行。 but according to naming convention first letter of Class Name must be in UpperCase , so you can name it as
MyString.java
但根据命名约定,类名的第一个字母必须在UpperCase中,因此您可以将其命名为
MyString.java
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.