为什么我不能在类中声明字符串?
public class Account {
public int pin;
public int accountnumber;
public string accounttype;
public double balance;
}
它告诉我字符串无法解析为类型。
public class Account {
public int pin;
public int accountnumber;
public string accounttype;
public double balance;
}
It tells me string cannot be resolved as a type.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它是带有大写 S 的
String
It's
String
with a capital S尝试
其他(
int
、double
)是所谓的原始数据类型,其中String
就像Account
“只是另一个类”。int
有一个“等价”(是的,我知道)(Integer
),就像String
Try
The others (
int
,double
) are so called primitive data types whereString
is likeAccount
"just another class".int
has an "equivalent" (yeah, I know) (Integer
), that is likeString
字符串不是原始类型。在 Java 中,对象/类命名约定的第一个字母大写。
您知道它是一个对象,因为它有方法,而且它基本上是一个字符数组。
此外,您应该将大多数类成员变量声明为私有(或受保护),除非有特定原因需要将其公开。
String is not a primitive type. In Java, objects/classes naming convention would have the first letter capitalized.
You know it is an object because it has methods and it is basically an array of characters.
Also you should declare most Class member variables as private (or protected) unless there is a specific reason you need to make it public.