[英]compiling Java error, cannot get constructor working
I am trying to code a simple bit of java but i cannot get it to compile I have defined the objects within my class as so 我试图编写一些简单的Java代码,但是我无法进行编译,因此我已经在类中定义了对象
public class teams
{
public char sponsor;
public char tires;
I am trying to set the default value of class sponsor to N/A 我正在尝试将课程赞助者的默认值设置为N / A
public teams()
{
this.sponsor = "N/A";
}
Can anyone figure out why it wont work? 谁能弄清楚为什么它行不通? Im fairly new to java and i know this is probably extremely simple, any help would be appreciated!
我是Java的新手,我知道这可能非常简单,任何帮助将不胜感激!
EDIT So thanks to Kevin Esche, I managed to get it to compile by using, 编辑因此,感谢Kevin Esche,我设法通过使用它来进行编译,
this.sponsor = 'N'; this.sponsor ='N';
How would I get the term N/A instead of just N? 我将如何获得术语N / A而不是N? Would I use unicode?, and if yes how do you format it?
我会使用unicode吗?如果是,您如何格式化它?
Either you make your sponsor a String 要么让您的赞助商成为String
public String sponsor;
Or you store only one character in it: 或者您只在其中存储一个字符:
sponsor = 'X';
Good Luck. 祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.