R
raphfrk
If you have 2 constructors for an object will it always match the most
specific.
public class ConstTest {
ConstTest(int x) {
System.out.println("Int: " + x );
}
ConstTest(Object o) {
System.out.println("Object: " + o.toString());
}
ConstTest(String str) {
System.out.println("String: " + str);
}
public static void main (String[] args) {
new ConstTest("A");
new ConstTest(1);
new ConstTest(new Double(1.7));
}
}
"new ConstTest("A");" matches both Object and String. Since String is
a sub-class of Object, does that mean that the String constructor
always matches first?
specific.
public class ConstTest {
ConstTest(int x) {
System.out.println("Int: " + x );
}
ConstTest(Object o) {
System.out.println("Object: " + o.toString());
}
ConstTest(String str) {
System.out.println("String: " + str);
}
public static void main (String[] args) {
new ConstTest("A");
new ConstTest(1);
new ConstTest(new Double(1.7));
}
}
"new ConstTest("A");" matches both Object and String. Since String is
a sub-class of Object, does that mean that the String constructor
always matches first?