The parent class of the Java subclass and the interface to be implemented have the same method/function conflict

Source: Internet
Author: User

The answer is, no. Subclasses first implement the methods of the parent class, although the methods and interfaces of the parent class are identical.

 class   father{ public  void   F () {}}  interface   sameinterface{ public  void   F ();}  class  son implements   sameinterface{ public  void   F () { //  

Note: This overlap may conflict when both the parent class and the interface declare an exception to be thrown. For example, the parent class declares exception 1, and the interface declares exception 2. When a subclass implements a member function, you cannot implement exception 1 or exception 2, and you can choose not to implement the exception.

classException1extendsexception{}classException2extendsexception{}classfather{ Public voidF ()throwsexception1{}}Interfacesameinterface{ Public voidF ()throwsException2;}classSonextendsFatherImplementssameinterface{ Public voidf () {//can only choose not to implement the exception, implementation exception1 or Exception2 will be error    }}

The parent class of the Java subclass and the interface to be implemented have the same method/function conflict

Related Article

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.