package com.imooc;public class Telphone { private float screen; private float cpu; private float mem; public Telphone() { System.out.println("construction methordwithout param execute"); } public Telphone(float newscreen,float newcpu,float newmem) { screen=newscreen; cpu=newcpu; mem=newmem; }}package com.imooc;public class initial { /*float screen; float cpu; float mem; public float getscreen() { return screen; }*/ /*public void setscreen(float newscreen) { screen=newscreen; }*/ public static void main(String[] args) { Telphone phone=new Telphone(); Telphone phone2=new Telphone(5.0f,1.4f,2.0f);System.out.println(phone2.screen+phone2.cpu+phone2.mem); }}
4 回答

勝利女神在微笑
TA貢獻(xiàn)67條經(jīng)驗(yàn) 獲得超59個(gè)贊
Telphone 這個(gè)類里給screen,cpu,mem這三個(gè)變量private設(shè)置成public即可


產(chǎn)品經(jīng)理不是經(jīng)理
TA貢獻(xiàn)481條經(jīng)驗(yàn) 獲得超143個(gè)贊
你把變量私有化了,不能直接通過對(duì)象.變量名進(jìn)行訪問,你可以在Telephone類里提供get方法,然后通過對(duì)象.getXXX方法進(jìn)行訪問。
添加回答
舉報(bào)
0/150
提交
取消