黑马程序员技术交流社区
标题:
拆箱和装箱
[打印本页]
作者:
qmayuan
时间:
2013-8-3 19:26
标题:
拆箱和装箱
现在有个Student类 构造方法是 Student(String name,Double math,Double cn,Double en)如果new对象 我应该怎么将int值传进去 Student stu = new Student(name,?,?,?);求高手指导下 谢谢~!
作者:
狐灵
时间:
2013-8-3 21:01
本帖最后由 狐灵 于 2013-8-3 21:05 编辑
源码如下
class Student {
String name;
Double math;
Double cn;
Double en;
public Student(String name, Double math, Double cn, Double en) {
this.name = name;
this.math = math;
this.cn = cn;
this.en = en;
}
public void printInfo() {
System.out.println("name : " + this.name + ", math : " + this.math
+ ", cn : " + this.cn + ", en : " + this.en);
}
}
public class TestStudent {
public static void main(String[] args) {
// Student stu = new Student("Jim", 90.0f, 90.0f, 90.0f);
// Student stu = new Student("Jim", 90, 90, 90);
Student stu = new Student("Jim", 90.0, 90.0, 90.0);
stu.printInfo();
}
}
复制代码
// Student stu = new Student("Jim", 90.0f, 90.0f, 90.0f);
这行报错
// Student stu = new Student("Jim", 90, 90, 90);
这行报错
正常编译输出
336.JPG
(13.28 KB, 下载次数: 10)
下载附件
2013-8-3 21:00 上传
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2