Page 221 - PowerPoint Presentation
P. 221

CAVITE STATE UNIVERSITY
                               T3 CAMPUS
                               Department of Information Technology          COSC 65 – Programming Languages


                  interface Drawing {   // interface declaration: by first user
                        void draw();
                  }
                  class Rectanlge implements Drawing {  // implementation: by second user
                        public void draw() {
                               System.out.println(“drawing rectangle…”);
                        }
                  }
                  class Circle implements Drawing {
                        public void draw() {
                               System.out.println(“drawing circle…”);
                        }
                  }
                  public class TestInterface2 {

                        public static void main(String[]args) {

                        Drawing sample = new Circle();
                        sample.draw();
                  }
                  }

               Multiple Inheritance in Java by Interface
                       If a class implements multiple interfaces, or an interface extends multiple interfaces, it
               is known as multiple inheritance.

                        Interface        Interface                  Interface         Interface
                               implements                                     extends
                                               Multiple Inheritance in Java
                                  Class                                       Interface


                              interface Printable {
                                     void print();
                              }
                              interface Showable {
                                     void show();
                              }

                              class A4 implements Printable, Showable {
                                     public void print() {
                                            System.out.println(“Hello”);
                                     }
                                     public void print() {
                                            System.out.println(“Welcome”);
                                     }
                              }
                              public class TestInterface3 {
                              public static void main(String[]args) {
                                     A4 obj = new A4();
                                     obj.print();
                                     obj.show();
                              } }




                                                                                                 Page | 80
   216   217   218   219   220   221   222   223   224   225   226