为什么我不能在类中声明字符串?

发布于 2025-01-05 11:06:52 字数 182 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

英雄似剑 2025-01-12 11:06:52

它是带有大写 S 的 String

It's String with a capital S

戏蝶舞 2025-01-12 11:06:52

尝试

public String accounttype;

其他(intdouble)是所谓的原始数据类型,其中String就像Account“只是另一个类”。
int 有一个“等价”(是的,我知道)(Integer),就像 String

Try

public String accounttype;

The others (int, double) are so called primitive data types where String is like Account "just another class".
int has an "equivalent" (yeah, I know) (Integer), that is like String

梦途 2025-01-12 11:06:52

字符串不是原始类型。在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文