封装D问题
package com.imooc;
public class Gouzao {
float screen;
float cpu;
float men;
public Gouzao(){
System.out.println("无参构造方法执行了");
}
public Gouzao(float newScreen,float newCpu,float newMen){
if(newScreen<3.5){
System.out.println("您输入的参数有误,自动赋值为3.5");
screen=3.5f;
}else{
screen=newScreen;
}
cpu=newCpu;
men=newMen;
System.out.println("有参的构造方法执行了"+screen+"\t"+cpu+"\t"+men);
}
}
package com.imooc;
public class IntGouzao {
public static void main(String[] args) {
Gouzao phone=new Gouzao();
Gouzao phone1=new Gouzao(4.0f,4.0f,5.2f);
phone.cpu=3.6f;
phone1.screen=6.0f;
}
}
无参构造方法执行了
有参的构造方法执行了4.0 4.0 5.2
结果没有变,为什么??