我用IntelliJ IDEA賦值,執行時沒有輸出?
幫忙看一下,為啥輸出沒有age那些賦值的參數。
public?class?IniTest1?{
????public?static?void?main(String[]?args)?{
????????Test1?test1=new?Test1();
????????test1.age=120;
????????test1.height=199f;
????????test1.name?="Allen";
????????test1.eat();
????????test1.talk();
????}
}public?class?Test1?{
????String?name;
????int?age;
????float?height;
????void?talk(){
????????System.out.println("You?can?talk?to?others");
????}
????void?eat(){
????????System.out.println("You?can?eat?what?you?want?to?");
????}
}只輸出了以下內容
You can eat what you want to?
You can talk to others
Process finished with exit code 0
2020-09-05
sdfasd
2020-07-21
我找到原因了。
2020-07-20
你的值確實賦給各個參數了,參數值已經是你賦給他的值,但是你并沒有print出這些屬性值,想要輸出的話,可以將這些參數寫入printf語句中