为什么我用有参的构造方法时候,只能输出语句,却不能给全局变量赋初值?
如题!求高手解释
public class Telphone {
float screen;
float cpu;
float mem;
public Telphone(){
System.out.println("无参的构造方法执行了!");
}
public Telphone(float newScreen,float newCpu,float newMem){
screen=newScreen;
cpu=newCpu;
mem=newMem;
System.out.println("有参的构造方法执行了!");
}
}
public class InitialTelphone {
public static void main(String[] args) {
Telphone phone=new Telphone();
Telphone PH=new Telphone(5.0f,1.4f,2.5f);
}
}