Saved Bookmarks
| 1. |
What is the result of the below program? |
|
Answer» class X { static int i = 1111; static{ i = i-- - --i; //L1 } { i = i++ + ++i; //L2 } } class Y extends X{ static{ i = --i - i--; //L3 } { i = ++i + i++; //L4 } } public class DriverClass{ public static void main(String[] args){ Y y = new Y(); System.out.println(y.i); //L5 } } Let us evaluate the expressions one by one: i = 1111 - 1109 = 2 L2 -> i = i++ + ++i;i = 0 + 2 = 2 L3 -> i = --i - i--;i = 1 - 1 = 0 L4 -> i = ++i + i++;i = 3 + 3 = 6 = y.i L5 -> |
|