Java-interface new Features

Source: Internet
Author: User

1. New features after Jdk8, default method
 Public classJavainterfaceImplementsDemo01, demo02{//The default method must be replicated in the inherited interface@Override Public voideat () {Demo01.Super. Eat ();//calling the writing format of a method in an inherited interfaceDemo02.Super. Eat (); }     Public Static voidMain (string[] args) {Newjavainterface (). Eat (); }}InterfaceDemo01 {default voideat () {System.out.println ("This is Demo01."); }    }InterfaceDemo02 {default voideat () {System.out.println ("This is Demo02."); }    }
If the class implements two or more interfaces, and two or more of these interfaces have the same default method, the implementing class must replicate the default method, or the compiler will fail, or if the class implements two or more than two interfaces, but a default method is unique to an interface. You can override or not rewrite the default method;

2. New features after Jdk8, static methods in the static method interface can directly use the interface call, but cannot be replicated or called in the implementation class of the interface, the class itself of the interface implementation class and its object cannot call the static method

Java-interface new Features

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.