关于封装修改属性的问题
package com.immoc;
import com.immoc.Telphone;
public class Telphone{
private float screen;//屏幕大小
private float cpu;
private float mem;//内存大小
public Telphone(float newScreen,float newCpu,float newMem){
screen=newScreen;
cpu=newCpu;
mem=newMem;
}
public static void main(String[] args) {
Telphone phone2=new Telphone(5.0f,1.4f,2.0f);
phone2.cpu=6.0f;
System.out.println("screen:"+phone2.screen);
System.out.println("cpu:"+phone2.cpu);
System.out.println("mem:"+phone2.mem);
}
}
我不是封装了吗? 为何简简单单一改便成功了 输出数据cpu是6.0