private 用法
视频中的 screen,cpu 和mem 都是private,为何只有screen需要用set 和get 方法获取,其他两个为何可以直接使用?(代码如下)
Public class Telephone(){
private float screen;
private float cpu;
private float mem;
public float getScreen(){
return screen;
}
public void setScreen(float newScreen){
screen=newScreen;
}
public Telphone(){
System.out.println("无参的构造方法执行了!“);
public Telphone(float newScreen,float newCpu,float newMem){
screen = newScreen;
cpu=newCpu;
mem=newMem;
}
public static void main(String[]args){
Telphone phone = new Telphone();
Telphone phone2 = new Telphone(5.0f,1.4f,2.0f);
//phone2.cpu = 6.0f;
phone2.setScreen(6.0f);
System.out.println("screen:"+phone2.getScreen());