我用IntelliJ IDEA賦值,執(zhí)行時沒有輸出?
幫忙看一下,為啥輸出沒有age那些賦值的參數(shù)。
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?"); ????} }
只輸出了以下內(nèi)容
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
你的值確實賦給各個參數(shù)了,參數(shù)值已經(jīng)是你賦給他的值,但是你并沒有print出這些屬性值,想要輸出的話,可以將這些參數(shù)寫入printf語句中