【发布时间】:2021-07-24 20:06:30
【问题描述】:
Java如何决定在下面的程序中调用哪个构造函数?
public class Test
{
Test(int a, int b)
{
System.out.println("a = "+a+" b = "+b);
}
Test(int a, float b)
{
System.out.println("a = "+a+" b = "+b);
}
public static void main (String args[])
{
byte a = 10;
byte b = 15;
Test test = new Test(a,b);
}
}
第一个以第二个参数为int的构造函数被调用,但是如果我删除第一个构造函数,那么另一个构造函数被调用。如果两个构造函数都存在,为什么要调用第一个?
【问题讨论】:
标签: java constructor type-conversion output implicit-conversion