找錯。報錯顯示cpu cannot be resolved to a variable、price cannot be resolved to a variable、
package?imooc;
?????????????//類名
public?class?Phone?{
???public?static?void?main(String[]?args){
???Phone?helloPhone=new?Phone();
???double?screen=89;
???float?cpu;
???float?price;
???helloPhone.goodPhone();
???helloPhone.xingNeng();
???}
???public?void?goodPhone(){
???System.out.println(price);
??System.out.println("好手機價格也好!");
???}
???public?float?xingNeng(){
// ???float?cpu=89.0f;
???System.out.println(cpu);
???return?cpu;
???}
}不是說成員變量的作用域是整個類的內部嗎?
2017-06-10
成員變量是指在類里但是在方法外面的變量,你的變量在main方法里面,是局部變量,不是成員變量。
2017-06-12
成員變量是在類里面,方法外面的叫成員變量;方法里面的是局部變量。