为了账号安全,请及时绑定邮箱和手机立即绑定

最后程序run的时候为什么就输出了3.5

最后程序run的时候为什么就输出了3.5,1.4和2.0为什么没出来

正在回答

3 回答

我把老师的两个类写在一个类里了:
package fangfa;
public class Goufa {
public static void main(String[] args) {
//Goufa phone = new Goufa();//执行构造方法
Goufa phone2=new Goufa(1.5f,1.4f,2.0f);
}
float screen;//成员变量
float cup;
float mem;
public Goufa(){//构造方法定义,方法名=类名
System.out.println("无参的构造方法执行了!");
}
public Goufa(float newScreen,float newCpu,float newMem){
if(newScreen<3.5f){
screen=3.5f;
System.out.println("输入的屏幕尺寸有问题,自动赋值为:"+screen);
}else{
   screen=newScreen;
   System.out.println("手机的屏幕尺寸为:"+screen);
}
cup=newCpu;
mem=newMem;
System.out.println("手机的cpu为:"+cup);
System.out.println("手机的内存为:"+newMem);
System.out.println("有参的构造方法执行了!");
}
}
运行结果:
输入的屏幕尺寸有问题,自动赋值为:3.5
手机的cpu为:1.4
手机的内存为:2.0
有参的构造方法执行了!
0 回复 有任何疑惑可以回复我~
#1

face1001 提问者

非常感谢!
2015-11-06 回复 有任何疑惑可以回复我~

同问,还是没有明白

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

最后程序run的时候为什么就输出了3.5

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信