Extending interfaces through inheritance

Source: Internet
Author: User

With inheritance technology, you can easily add new method declarations for an interface or combine several interfaces into a new interface. In both cases, you end up with a new interface, as shown in the following example:

: Horrorshow.java
//Extending a interface with inheritance

interface Monster {
  void menace ();
}

Interface Dangerousmonster extends Monster {
  void Destroy ();
}

Interface Lethal {
  void Kill ();
}

Class Dragonzilla implements Dangerousmonster {public
  void Menace () {} public
  void Destroy () {}
}

Interface Vampire 
    extends Dangerousmonster, lethal {
  void Drinkblood ();
}

Class Horrorshow {
  static void U (Monster b) {b.menace ();}
  static void V (Dangerousmonster d) {
    d.menace ();
    D.destroy ();
  }
  public static void Main (string[] args) {
    Dragonzilla if2 = new Dragonzilla ();
    U (IF2);
    V (IF2);
  }
///:~

Dangerousmonster is a simple extension of the monster, which eventually generates a new interface. This was achieved in the Dragonzilla.
Vampire syntax is only available when inheriting interfaces. In general, we can only apply the extends (extended) keyword to a single class. However, since interfaces may be composed of multiple other interfaces, extends may reference multiple underlying interfaces when building a new interface. As you can see, the name of the interface is simply separated with commas.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.