Hello! This is my first time in this forum. I hope that you guys can help me on this theory question..
It is about polymorphism and I'm not too good at it.
--------------------------------class Food{ public String show(Food f){ return("Food Food"); } /* public String show(Fish f){ return("Food Fish"); }*/ } class Fish extends Food{ public String show(Food f){ return("Fish Food"); } public String show(Fish f){ return("Fish fish"); } } class Poly{ public static void main(String args[]){ Food fo = new Fish(); Fish fi = new Fish(); System.out.print(fo.show(fi)); } }
class Food{ public String show(Food f){ return("Food Food"); } public String show(Fish f){ return("Food Fish"); } } class Fish extends Food{ public String show(Food f){ return("Fish Food"); } public String show(Fish f){ return("Fish fish"); } } class Poly{ public static void main(String args[]){ Food fo = new Fish(); Fish fi = new Fish(); System.out.print(fo.show(fi)); } }
Why is it that code 1 gives me Fish Food
and Code 2 gives me Fish Fish
The only difference with them, is the commented line. THANK YOU!