Page 196 - CTS - CSA TP - Volume 2
P. 196
COMPUTER SOFTWARE APPLICATION - CITS
public static void main(String[] args) {
Square square = new Square();
square.draw();
square.color();
}
}
Explanation:
1. Base Interface (Shape):
• Defines a base interface named Shape with a single abstract method draw.
2. Extended Interface (Colorable):
• Extends the Shape interface using the extends keyword.
• Introduces an additional abstract method color.
3. Class Implementation (Square):
• Implements the extended interface Colorable.
• Provides concrete implementations for both draw and color methods.
4. Main Class (InterfaceExtensionExample):
• Creates an instance of the Square class.
• Demonstrates the usage of both draw and color methods through the square object.
Output:
This example illustrates how an interface (Colorable) can extend another interface (Shape) to inherit its methods
while adding new methods. The class Square implements the extended interface, providing implementations for
all abstract methods. The main method demonstrates the usage of methods from both the base and extended
interfaces through an instance of the implementing class.
181
CITS : IT & ITES - Computer Software Application - Exercise 114