java - Method overrding passing null object -
this question has answer here:
i unable understand why program prints string
class aa { void m1(object o) { system.out.println("object "); } void m1(string o) { system.out.println("string "); } } public class stringorobject { public static void main(string[] args) { aa = new aa(); a.m1(null); } }
please me understand how works print sting rather object
dave newton's comment correct. call method goes specific possible implementation. example be:
class foo {} class bar extends foo {} class biz extends bar {} public class main { private static void meth(foo f) { system.out.println("foo"); } private static void meth(bar b) { system.out.println("bar"); } private static void meth(biz b) { system.out.println("biz"); } public static void main(string[] args) { meth(null); // biz printed } }
Comments
Post a Comment