Page 138 - CTS - CSA TP - Volume 2
P. 138
COMPUTER SOFTWARE APPLICATION - CITS
Output:
The output displays the calculated areas for each shape.
Conclusion:
• The program effectively demonstrates the concept of method overloading to provide a single, consistent
interface (calculateArea) for calculating areas of different geometrical shapes.
• The choice of appropriate data types (int, long, double) for different parameters adds flexibility to the
program.
Overall, the program showcases a clean and modular approach to handle various geometrical calculations in a
concise manner.
TASK 2: Overloaded Methods for String Concatenation
// String Concatenation using Overloaded Methods
import java.io.*;
public class StringConcatenator {
// Method to concatenate two strings
public static String concatenate(String str1, String str2) {
return str1 + str2;
}
// Method to concatenate three strings
public static String concatenate(String str1, String str2, String str3) {
return str1 + str2 + str3;
}
public static void main(String[] args) {
String str1 = “Hello, “;
String str2 = “world!”;
String str3 = “How are you?”;
// Concatenate strings using overloaded methods
System.out.println(concatenate(str1, str2));
System.out.println(concatenate(str1, str2, str3));
}
}
Output:
123
CITS : IT & ITES - Computer Software Application - Exercise 98 CITS : IT & ITES - Computer Software Application - Exercise 98