The document describes a class with three overloaded num_calc() methods that perform different calculations based on the argument types: 1) Takes an int and char, calculates square or cube, 2) Takes two ints and a char, calculates product or sum, 3) Takes two Strings and prints whether they are equal. The class implements the overloaded num_calc() methods to handle the different argument types and perform the specified calculations or comparison.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
1K views1 page
Function Overloading - Icse Board Question 2009
The document describes a class with three overloaded num_calc() methods that perform different calculations based on the argument types: 1) Takes an int and char, calculates square or cube, 2) Takes two ints and a char, calculates product or sum, 3) Takes two Strings and prints whether they are equal. The class implements the overloaded num_calc() methods to handle the different argument types and perform the specified calculations or comparison.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1
System.out.
println("The two strings are not equal");
Function Overloading - } } ICSE BOARD QUESTION } 2009 /** * Design a class to overload a function num_calc() as follows: * * void num_calc(int num, char ch) with one integer argument and one char * argument, computes the square of integer argument if choice ch is 's' * otherwise find its cube. * * void num_calc(int a, int b, char ch) with two integer arguments and * character argument. It computes the product of integer arguments if ch * is 'p' else adds the integers. * * void num_calc(String s1, String s2) with two string arguments, which * prints whether the strings are equal or not * */ public class questionSEVEN2009 { public void num_calc(int num, char ch) { if(ch=='s') { int square=num*num; System.out.println("The square of the number is = "+ square); } else { int cube=num*num*num; System.out.println("The cube of the number is = "+ cube); } } public void num_calc(int a, int b, char ch) { if(ch=='p') { int product=a*b; System.out.println("The product of the two numbers is = "+ product); } else { int sum=a+b; System.out.println("The sum of the two number is = "+ sum); } } public void num_calc(String s1, String s2) { if(s1.equals(s2)) { System.out.println("The two strings are equal"); } else {