Page 368 - Computer_Science_F5
P. 368

Program Example 5.25:

               Java program to demonstrate multiple interface


                  Java program to demonstrate multiple interface                                   Chapter Five: Object oriented programming with Java
          FOR ONLINE READING ONLY
                  interface One {
                    public void methodA(); // This is interface method
                  }
                  interface Two {
                    public void methodB(); // This is interface method
                  }
                  class OnRoadTest implements One, Two {
                    public void methodA() {
                      System.out.println(“We test the movie of interface..”);
                    }
                    public void methodB() {
                      System.out.println(“We are to make object from this interface...”);
                    }
                  }
                  class Main {
                    public static void main(String[] args) {
                      OnRoadTest makeObj = new OnRoadTest ();
                      makeObj.methodA();
                      makeObj.methodB();
                    }
                  }


                Output:





                                  Figure 5.27: Output of multiple interface program



                  Activity 5.9:                              Exercise 5.4:

                Visualisation of Java interface code     1.  Explain the concept of inheritance
                execution                                   in Java and how it allows classes
                                                            to inherit properties and behaviors
               Use Jeliot 3 or later version, visualise     from other classes. Provide an
               the step by step execution  of java          example of inheritance in action.
               program  to explore  about interface      2.  Describe the difference between
               in Java. Use the code in Program             single inheritance and multiple
               Example 5.25.                                inheritance in Java. How does Java


                                                    359
               Student’s Book  Form Five



     Computer Science Form 5.indd   359                                                     23/07/2024   12:34
   363   364   365   366   367   368   369   370   371   372   373