java程序错哪了

http://img.mukewang.com/5981e2b500018b4f13660768.jpg

http://img.mukewang.com/5981e2b70001aa3e13660768.jpg

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);

}


}


溯源1
浏览 1806回答 4
4回答

胜利女神在微笑

Telphone 这个类里给screen,cpu,mem这三个变量private设置成public即可

慕数据8267187

ASPGNKAQDZMIOXJQMNJGCULBSBMPOOEZSOIBBBKQHYARXNWGYQXNDLXUAQXESHQXFRFBHOBYGVFMJPWZPJZFLHXNGMFIMCSDCYBRORVXUAFVGISEYEOXDDQYVPESXNRKHREAWBUOKHLRXXXGNQXQNWZUDNNNIAWLOAEUNDKUNJDTGFJKGRONFQUKUBRUUKEXIMSPPGMFFVLOIFREESEKXDXJXZMDVLOVYOEXNAKXZQMWIDJEWBULIIHHIVYRAYKAQGMQGMWDHDQZWDJBHKTWYYCYLTJACMMPABXOUXENXNDZVUDXNLOKSGSDYGDJPNWJYKHGJRFWFPFZULSYQMJQDUXUAGLOSHKDOXXFEEMJGBRZPSIEHDSIRMCZVDUDMJSHOJMPLITVYBQUNBEZJZWFUXADMNQGCLBMHXNPUCTILVZNJFBYNCYBLHEBOOUDJIYYHQXKTDJTPYYLYSVJSPVFCIERHYLMIIREPUPBWWPWLSBCMPBBRQHATJMFMBELIPTWPFHQGWSIRUKLOQTCUPMDMWZORWTISUXHDMVNCFBQYBDGQNOLBDMJCXUWFIXUQGWYUCFNKHXGWYVFWYUDAWYIYUQALGWFUSBRNQRHRGDSCFBRNPMIBPMOEUKAXNETDSVENXTISBDAXFBLHKHDZCTDEZBYVEHDGDMWTUKAQMISULHEFOQZCRULNEOXCXBRUDGPYIEAFUDSWGWEHQGCJRBFTCNWSCLNVQTJGBQMWFOXHJRUCLURUJFVBWSPFOEUDGPMODSDYHXNJMVRYBXTJTIYZBMVAVKHQGPFIRMIQLNDZJMCLVLNHUKZJSIEHKZIJSHQBXNWZXGPIQGJEGDSVLUDIJZPYTWLULVRWRNLHKAKMPRZDFHYOXNQLNDGQSJFBEFVEOWMGCLCYBQTWMIPZPKHRNDHDAQFZOJOWMVZPTWLPKHDGXZUKSCFKZKFVXHXNWFN

秃头披风侠0

按理说 不通过get方法访问私有成员 编译都过不了吧

溯源1

那为什么,把打印输出去掉,就可以用了

产品经理不是经理

你把变量私有化了,不能直接通过对象.变量名进行访问,你可以在Telephone类里提供get方法,然后通过对象.getXXX方法进行访问。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java