Java basic knowledge traps (8)
For the difference between "&" and "&", we all know that "&" is a bitwise operator and "&" is a logical operator. refer to the following code: public static void main (String [] args) throws Exception {int a = 1; int B = 2; int c = a & B; if (a> = 1 & B> = 1) {System. out. println ("& condition 1");} if (a >=2 & (B = 3) >=3) {System. out. println ("& condition 2");} System. out. println (B); System. out. println (c) ;}then the output: & condition 1 shows that when the second condition is judged, & if a short circuit is performed, the B = 3 operation is not performed. If you replace & with &, see the code: public static void main (String [] args) throws Exception {int a = 1; int B = 2; int c = a & B; if (a> = 1 & B> = 1) {System. out. println ("& condition 1");} if (a >=2 & (B = 3) >=3) {System. out. println ("& condition 2");} System. out. println (B); if (a> = 2 & (B = 3)> = 3) {System. out. println ("& Condition 3");} System. out. println (B); System. out. println (c) ;}check the output: & condition 1. This & Symbol does not generate a short circuit. The following judgment is also made. Polymorphism is very familiar to programmers. If you are familiar with polymorphism, I 'd like to say that the Internet is much better. First, polymorphism should be a runtime behavior. This is especially important! Many places on the Internet have said that rewriting and overloading are polymorphism. However, in some places and blogs, it is suggested that reload should not be considered as a polymorphism !! Class Parent {public void doing () {System. out. println ("Parent --> do") ;}} class Child extends Parent {@ Override public void doing () {System. out. println ("Child --> do");} public void run () {System. out. println ("Child --> run") ;}} check the call code: public static void main (String [] args) throws Exception {Parent p = new Child (); p. doing (); p. run ();} p. doing (); this can be called accurately, but p. run () is a compilation error because its method is not defined in the Parent. If you need to call It must be defined as Child. 1 Child p = new Child ();