hello2.screen=6.0f與hello2.screen(6.0f)區(qū)別
在類Telphone屬性設(shè)置為public?screen中,在main方法中寫成對(duì)象名.屬性()即hello2.screen=6.0f是對(duì)screen賦值,能輸出結(jié)果;但是寫成hello2.screen(6.0f)就不對(duì),顯示錯(cuò)誤,請(qǐng)問這是什么原因,這兩者有什么區(qū)別?
在類Telphone屬性設(shè)置為public?screen中,在main方法中寫成對(duì)象名.屬性()即hello2.screen=6.0f是對(duì)screen賦值,能輸出結(jié)果;但是寫成hello2.screen(6.0f)就不對(duì),顯示錯(cuò)誤,請(qǐng)問這是什么原因,這兩者有什么區(qū)別?
2017-03-16
舉報(bào)
2017-03-17
hello2.screen=6.0f是對(duì)屬性進(jìn)行賦值,而
hello2.screen(6.0f)是調(diào)用screen方法了
2017-03-16
hello2.screen是直接對(duì)屬性進(jìn)行賦值。hello2.screen是當(dāng)screen為private是不能直接賦值,必須通過方法來。
2017-03-16
用hello2.getscree(6.0f)賦值 還要看Telephone類中 屬性 scree前的修飾符 如果是 prinvae 就不能用hello2.screen(6.0f)賦值 要用get ? ? ?如果是public 就可以用hello2.scree(6.0f)賦值