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