Page 184 - CITS - CSA - TP (Volume 2) - Hindi
P. 184

कं  ूटर सॉ वेयर ए ीके शन - 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 - कं  ूटर सॉ वेयर ए ीके शन - अ ास 111
   179   180   181   182   183   184   185   186   187   188   189