Page 194 - CTS - CSA TP - Volume 2
P. 194

COMPUTER SOFTWARE APPLICATION - CITS




                   System.out.println(“Showing...”);
               }
           }


           // Main class

           public class MultipleInterfacesExample {
               public static void main(String[] args) {
                   Display display = new Display();
                   display.print();

                   display.show();
               }
           }


           Explanation:

           1.  Interface Definitions (Printable and Showable):
              •  The code defines two interfaces: Printable and Showable.
              •  Each interface declares a single abstract method (print in Printable and show in Showable).
           2.  Class Implementation (Display):

              •  The Display class implements both the Printable and Showable interfaces.
              •  It provides concrete implementations for the print and show methods.
           3.  Method Implementations (print and show):
              •  The print method prints “Printing...” to the console.
              •  The show method prints “Showing...” to the console.
           4.  Main Class (MultipleInterfacesExample):

              •  The main method creates an instance of the Display class named display.
              •  It demonstrates the use of the print and show methods through the display object.
           Output:



















           In summary, this example illustrates the implementation of multiple interfaces (Printable and Showable) in a class
           (Display). The class provides concrete implementations for the methods defined in each interface. The main
           method demonstrates the usage of these methods through an instance of the implementing class, showcasing
           how a class can incorporate multiple interfaces in Java.




                                                           179
 CITS : IT & ITES - Computer Software Application - Exercise 113  CITS : IT & ITES - Computer Software Application - Exercise 113
   189   190   191   192   193   194   195   196   197   198   199