Computer Science, asked by tishir22, 10 months ago

Design a class to overload a function compare() as follows:
(a) void compare(int, int): to compare two integer values and print the greater of the two integers.
(b) void compare(char, char): to compare the numeric values of two characters and print the character with higher numeric value.
(c) void compare(String, String): to compare the length of the two strings and print the longer of the two​

Answers

Answered by jefferson7
29

Design a class to overload a function compare() as follows:

(a) void compare(int, int): to compare two integer values and print the greater of the two integers.

(b) void compare(char, char): to compare the numeric values of two characters and print the character with higher numeric value.

(c) void compare(String, String): to compare the length of the two strings and print the longer of the two​

Explanation:

class overload{

void compare (int a , int b)

{

if (a>b)

System.out.print(a);

else

System.out.print(b);

void compare(char a, char b);

int x = (int) a;

int y = (int) b;

x= (char)x;

System.out.println(x);

}

else

{

y= (char)y;

System.out.println(y);

}

void compare(String1, String 2);

{

if(s1.length() >s2.length () )

System.out.println(s1)

else

System.out.println(s2)

}

}

Answered by sujal874237
11

Explanation:

here is your answer

please follow me

mark this answer as brainliest

Attachments:
Similar questions