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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -