This article was posted on my blog
This time I'm talking about the difference between & and &&, we all know that & is a bitwise operator, and && is a logical operator, see 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:
&& conditions 120
As can be seen, the second condition is judged when && a short circuit does not perform B = 3; What if we change && into &, how to look at 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); }
Look at the output:
&& Conditions 1230
This & symbol does not produce a short-circuit function and will be judged below.
Polymorphic This is very familiar to programmers, familiar with me or to say that the internet is much better, first polymorphic should be a run-time behavior, this is particularly important! Many places on the web say that rewriting and overloading are polymorphic behaviors. But there are some places as well as blogs that explain that overloading is not interpreted as polymorphic!!
Class parent{public void doing () { System.out.println ("Parent-to-do");} } Class Child extends the Parent { @Override public Void doing () { System.out.println ("child-to-do"); } public void Run () { System.out.println ("child-to-run");} }
Look at the calling code:
public static void Main (string[] args) throws Exception { Parent p = new Child (); P.doing (); P.run (); }
P.doing (); This can be called exactly, however P.run () is a compilation error because its method is not defined in the parent class, and needs to be defined as child if it needs to be called.
Child p = new Child ();
to understand more, you can see here:
http://blog.csdn.net/cyq1028/article/details/6879088
http://www.cnblogs.com/mengdd/archive/2012/12/25/2832288.html
come here first this time. Keep a record of every bit of drip!
Java Basics Traps (eight)