Seems to be due to it not recognising the object been passed. So it assumes the "child(Cat c)".
If you uncomment the other lines you have more than one receiving unknown objects and it becomes ambiguous. -Nando Sent from my Sinclair ZX81 On 16 February 2012 07:04, ABHISHEK TRIPATHI <[email protected]> wrote: > Hi, > Can you plz tell why output is coming as Cat not Animal? > Also if I un-comment all lines, I get compile time error. > > thanks > Abhi > > *********************************** > package Overload; > public class Animal { > > // void child(Dog d) {System.out.println(" Dog");} > void child(Cat c){System.out.println(" Cat");} > void child(Animal a){System.out.println(" Animal");} > // void child(Mouse m){System.out.println(" Mouse");} > // private void child(Cat x){} > > public static void main(String[] args) { > Animal an=new Animal(); > an.child(null); > } > } > ************ > class Dog extends Animal{} > class Cat extends Animal{} > class Mouse extends Dog{} > > > -- > You received this message because you are subscribed to the Google Groups > "JPassion.com: Java Programming" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/jpassion_java?hl=en. > -- You received this message because you are subscribed to the Google Groups "JPassion.com: Java Programming" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/jpassion_java?hl=en.
