G
gokul.b
please look at the code snippet below:-
public class PowerSupply {
public PowerSupply(Object voltage){
System.out.println ("PowerSupply(Object) executed");
}
public PowerSupply(String voltage){
System.out.println ("PowerSupply(String) executed");
}
public PowerSupply(){
System.out.println ("No argument constructor execute");
}
public static void main(String[] args) {
PowerSupply ps = new PowerSupply(null);
}
}
which is the constructor invoked?
The answer is the String constructor is invoked. I do not understand
why the Object constructor wasnt invoked.
in the case of" ps = new PowerSupply((Object)null)", the Object
constructor is invoked.
Any insight into the java' interpretation of null is greatly
appreciated!
thx
g
public class PowerSupply {
public PowerSupply(Object voltage){
System.out.println ("PowerSupply(Object) executed");
}
public PowerSupply(String voltage){
System.out.println ("PowerSupply(String) executed");
}
public PowerSupply(){
System.out.println ("No argument constructor execute");
}
public static void main(String[] args) {
PowerSupply ps = new PowerSupply(null);
}
}
which is the constructor invoked?
The answer is the String constructor is invoked. I do not understand
why the Object constructor wasnt invoked.
in the case of" ps = new PowerSupply((Object)null)", the Object
constructor is invoked.
Any insight into the java' interpretation of null is greatly
appreciated!
thx
g