Hi Pho- They are different. Method overloading is when you have methods with the same name, but different paramater lists. Such as: public void myTest(){} public void myTest(int a){} public int myTest (String s){return 1;}
Polymorphism is the ability of an object to be declared that of a super object type and maintain the methods in the actual type class. i.e. Object obj = new String("Hi"); obj.equals("Hi");//true because the equals method is used from the String class Kyle
Here's a simple polymorphism problem. I want to create a method of this signature: public void printType( Object o ); e.g. Boolean b = new Boolean(true); Someclass.printType( b ); // prints "Boolean" boolean b2 = true; Someclass.printType( b2 ); // prints "boolean" The second invocation gives me a compile error: printType(java.lang.Object) in Someclass cannot be applied to (boolean) What am I missing ? Thanks Pho
>> boolean b2 = true; You are trying to pass a primitive to a method that accepts an object. That's why you are getting a compile error. The first invocation is legal because "Boolean" is an object.
Bosun
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley