class B {
private static int x1;
public void setX(int x) {x1 = x;}
public int getX() {return x1;}
public static void main(String[] args) {
int i1 = 0, j1 = 0;
do {
System.out.print(j1++);
assert (i1 = j1 + x1) < 6;
} while (i1 < 3);
}}
if setX method is never invoked then what would be the result?
Ans :
With assertions enabled it prints 012.
With assertions disabled it attempts to print an infinite sequence of numbers
Can anyone explain this???
private static int x1;
public void setX(int x) {x1 = x;}
public int getX() {return x1;}
public static void main(String[] args) {
int i1 = 0, j1 = 0;
do {
System.out.print(j1++);
assert (i1 = j1 + x1) < 6;
} while (i1 < 3);
}}
if setX method is never invoked then what would be the result?
Ans :
With assertions enabled it prints 012.
With assertions disabled it attempts to print an infinite sequence of numbers
Can anyone explain this???