The implements method cannot be used for interface inheritance.

Source: Internet
Author: User
In the group, a netizen asked a question about the interface:
Interface I {
Void setvalue (INT Val );
Int getvalue ();
}

Definition:
(A) Class A extends I {
Int value;
Void setvalue (INT Val) {value = val ;}
Int getvalue () {return value ;}
}

Definition B:
(B) interface B extends I {
Void increment ();
}

Definition C:
(C) interface D implements I {
Void increment ();
}

Definition D:
(D) Class E implements I {
Int value;
Public void setvalue (INT Val) {value = val ;}
}

Which of the following statements is correct? Of course, B is the answer first.

In option A, Class A cannot implement interfaces through the extends keyword. Class implementation interfaces must use the implements keyword. A class can implement multiple interfaces at the same time, but only one extends class can be used. Option B is correct. to inherit from another interface, you must use the extends keyword, and you can use extends to implement multiple interfaces at the same time. Option C is incorrect. Option D is obvious, and the interface method is not implemented.
It must be noted that, although the integrated interface uses the extends keyword, it cannot be used to inherit abstract classes in the interface. Multiple Interfaces can be implemented at the same time.

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.