0% нашли этот документ полезным (0 голосов)
2K просмотров1 страница

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.

Загружено:

binduann
Авторское право
© © All Rights Reserved
Мы серьезно относимся к защите прав на контент. Если вы подозреваете, что это ваш контент, заявите об этом здесь.
Доступные форматы
Скачать в формате DOCX, PDF, TXT или читать онлайн в Scribd
0% нашли этот документ полезным (0 голосов)
2K просмотров1 страница

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.

Загружено:

binduann
Авторское право
© © All Rights Reserved
Мы серьезно относимся к защите прав на контент. Если вы подозреваете, что это ваш контент, заявите об этом здесь.
Доступные форматы
Скачать в формате DOCX, PDF, TXT или читать онлайн в Scribd

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
{

Вам также может понравиться