Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class with two methods each having the same name sayadd. One method shou

ID: 3613840 • Letter: W

Question

Write a class with two methods each having the same name sayadd. One method should accept two integers as parameters and returntheir sum. The other method should accept two strings as parametersand return the string formed by concatenation of the two strings.In main call the method Add first by passing integer parameters andthen by passing string parameters and obtain their return values inmain and print them. Show that the overloaded method calls theappropriate method according to the parameters passed to it.

Explanation / Answer

please rate - thanks import java.util.*; public class over { public static void main(String []args) {String cat; int sum; sum=add(4,5); cat=add("abc","def"); System.out.println("added= "+sum+" Concatenated= "+cat); } public static int add(int n,int m) {System.out.println("In integer- parameters are: "+n+" "+m); return n+m; } public static String add(String n,String m) {System.out.println("In String- parameters are: "+n+" "+m); return n+m; } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote