String Handling — Question 35
Back to all questionsQuestion 22
Design a class to overload a function num_calc() as follows:
- void num_calc(int mini, char ch) with one integer argument and one character argument, computes the square of integer argument if choice ch is 's' otherwise finds its cube.
- void num_calc (int a, int b, char ch) with two integer arguments and one 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.
import java.util.Scanner;
public class KboatChoiceOverload
{
void num_calc(int mini, char ch) {
if (ch == 's') {
long sq = mini * mini;
System.out.println("Square = " + sq );
}
else {
long cube = mini * mini * mini;
System.out.println("Cube = " + cube);
}
}
void num_calc(int a, int b, char ch) {
if (ch == 'p') {
long prod = a * b;
System.out.println("Product = " + prod );
}
else {
long sum = a + b;
System.out.println("Sum = " + sum);
}
}
void num_calc(String s1, String s2) {
if(s1.equals(s2))
System.out.println("Strings are equal");
else
System.out.println("Strings are not equal");
}
}Output






Key Concepts Covered
This question tests your understanding of the following concepts from the chapter String Handling: Question, Design, Class, Overload, Num, Calc. These are fundamental topics in Computer Applications that students are expected to master as part of the ICSE Class 10 curriculum.
A thorough understanding of these concepts will help you answer similar questions confidently in your ICSE examinations. These topics are frequently tested in both objective and subjective sections of Computer Applications papers. We recommend revising the relevant section of your textbook alongside practising these solved examples to build a strong foundation.
How to Approach This Question
Read the question carefully and identify what is being asked. Break down complex questions into smaller parts. Use the terminology and concepts discussed in this chapter. Structure your answer logically — begin with a definition or key statement, then provide supporting details. Review your answer to ensure it addresses all parts of the question completely.
Key Points to Remember
- Write programs with proper indentation and comments.
- Trace through your code with sample inputs to verify correctness.
- Explain the logic behind each step of your solution.
- Familiarise yourself with common library functions and methods.
Practice more questions from String Handling — Computer Applications, Class 10 ICSE