Page 185 - CTS - CSA TP - Volume 2
P. 185
COMPUTER SOFTWARE APPLICATION - CITS
}
}
// Example 4: Interface with Static Method
interface Utility {
static void showInfo() {
System.out.println(“This is a utility interface.”); // Static method with implementation
}
void performTask(); // Abstract method
}
// Example 5: Interface Inheritance
interface Flyable {
void fly();
}
interface Swimmable {
void swim();
}
// Combined interface inheriting from Flyable and Swimmable
interface FlyingSwimmingCreature extends Flyable, Swimmable {
// No additional methods needed
}
// Main class
public class InterfaceExample implements Printable, Shape, Greeting, Utility, FlyingSwimmingCreature {
// Implementation of Printable interface method
@Override
public void print() {
System.out.println(“Printing...”);
}
// Implementation of Shape interface method
@Override
public double calculateArea() {
return PI * 2 * 2; // Area of a circle with radius 2
}
// Implementation of Greeting interface method
@Override
public void greet() {
System.out.println(“Hello!”);
}
// Implementation of Utility interface method
@Override
170
CITS : IT & ITES - Computer Software Application - Exercise 111