Which constructor is chosen when passing null?

In the following example, I have 2 constructors: one that takes a String and one that takes a custom object. On this custom object a method "getId()" exists which returns a String.

public class ConstructorTest {
 private String property;

 public ConstructorTest(AnObject property) {
  this.property = property.getId();
 }

 public ConstructorTest(String property) {
  this.property = property;
 }

 public String getQueryString() {
  return "IN_FOLDER('" + property + "')";
 }
}

If I pass null to the constructor, which constructor is chosen and why? In my test the String constructor is chosen, but I do not know if this will always be the case and why.

I hope that someone can provide me some insight on this.

Thanks in advance.

7
задан 26 October 2010 в 08:03
поделиться