String Handling — Question 34
Back to all questionsQuestion 21
Design a class to overload a function Joystring() as follows:
- void Joystring(String s, char ch1, char ch2) with one string argument and two character arguments that replaces the character argument ch1 with the character argument ch2 in the given string s and prints the new string.
Example:
Input value of s = "TECHNALAGY"
ch1 = 'A',
ch2='O'
Output: "TECHNOLOGY" - void Joystring(String s) with one string argument that prints the position of the first space and the last space in the given string s.
Example:
Input value of s = "Cloud computing means Internet based computing"
Output:
First index : 5
Last index : 36 - void Joystring (String s1, String s2) with two string arguments that combines the two strings with a space between them and prints the resultant string.
Example:
Input value of s1 ="COMMON WEALTH"
Input value of s2 = "GAMES"
Output: COMMON WEALTH GAMES
(use library functions)
public class KboatStringOverload
{
public void joystring(String s, char ch1, char ch2) {
String newStr = s.replace(ch1, ch2);
System.out.println(newStr);
}
public void joystring(String s) {
int f = s.indexOf(' ');
int l = s.lastIndexOf(' ');
System.out.println("First index: " + f);
System.out.println("Last index: " + l);
}
public void joystring(String s1, String s2) {
String newStr = s1.concat(" ").concat(s2);
System.out.println(newStr);
}
public static void main(String args[]) {
KboatStringOverload obj = new KboatStringOverload();
obj.joystring("TECHNALAGY", 'A', 'O');
obj.joystring("Cloud computing means Internet based computing");
obj.joystring("COMMON WEALTH", "GAMES");
}
}Output

Answer: ch1
Key Concepts Covered
This question tests your understanding of the following concepts from the chapter String Handling: Question, Design, Class, Overload, Joystring, Follows. 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