The Java class references both the parent class and the interface's member variables, which need to indicate whether the parent class or the interface

Source: Internet
Author: User

Code

 PackageCom.qhong; Public classMainextendsBImplementsa{ Public Static voidMain (string[] args)throwsException {NewMain (). Action ();; }     Public voidaction () {System.out.println (Super. x);        System.out.println (a.x); //System.out.print (x);    }}Interfacea{intx = 0;//default is public static final}classb{intx = 1;}

Output:

10

If the comment is canceled, the error:

Error: (+) Java: Reference to x is ambiguous com.qhong.b variables x  and COM.QHONG.A in variable x match

Two small questions to keep an eye on

First logical operation &| with conditional operation &&| | Difference

The basic difference is not small, can be logical calculation, but the condition operation has a short-circuit phenomenon, that is, once the value of the expression can be confirmed, then the remaining parts will not be executed.

int a = 0int b = 0if/If// after =3 , B=3. 

The second, in the code run, return,finally that first execution, if finally there is a return inside

If there is no return in the finally Return,try, then the return within the Try->finally->try is executed first

If there is a return in the return,try inside the Finally, then the return within the order try-finally->finally is executed

http://blog.csdn.net/junli_chen/article/details/49612463

http://blog.csdn.net/junli_chen/article/details/49613851

http://blog.csdn.net/junli_chen/article/details/49624025

http://blog.csdn.net/junli_chen/article/details/49659771

The Java class references both the parent class and the interface's member variables, which need to indicate whether the parent class or the interface

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.