Example of Function Overloading
class Overload
{
void compare( int a, int b)
{
if (a >b)
System.out.println(a);
else if (b > a)
System.out.println(b);
}
void compare(char ch1, char ch2)
{
if ( (int) ch1 > (int)ch2)
System.out.println(ch1);
else
System.out.println(ch2);
}
void compare( String s1, String s2)
{
if( s1.length() >s2.length() )
System.out.println(s1);
else
System.out.println(s2);
}
}
No comments:
Post a Comment