Can the Java interface have a specific implementation

Source: Internet
Author: User

Public interface S {


}


Public interface B {

Public static final S S = new S () {
Public String toString () {
Return "I realized in the interface";
}
public void dostring (String s) {
SYSTEM.OUT.PRINTLN ("I implemented on the interface");
}
};
}


public class Test {

public static void Main (string[] args) {
String s = b.s.tostring ();
System.out.println (s); I implemented it in the interface

}
}

(First of all, although my JDK version is 1.6, 1.8 can write a specific implementation in the interface)

This is a concrete implementation of the interface but my eclipse cannot call to dostring (), so the S interface can only override the 9 major methods of object

Although it is meaningless to make a concrete implementation of the interface by means of anonymous internal classes,

But it does not mean that the interface is not specifically implemented, but that it is not allowed




This article is from the "The_monster" blog, make sure to keep this source http://zzqnobody.blog.51cto.com/7059797/1622388

Can the Java interface have a specific implementation

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.