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