Hi sreedhar,
For the following program using assert at //1 and //2
public class Test{
public static int y;
public static int foo ( int x){
System.out.println("foo");
return y=x;
}
public static int bar(int z){
System.out.println("bar");
return y=z;
}
public static void main(
String args[]){
int t=2;
System.out.println("Before assert");
assert t>4:bar(7); //1
assert t>1:foo(8); //2
System.out.println("done : y : "+y);
}
}
1)You have to compile this java file as, "javac -source 1.4 Test.java" to enable assert.
2)Also while running you have to use, "java -ea Test" to enable assertion during runtime.
If you do the above two things, for //1 you will get an java.lang.AssertionError as the condition (t>4) is false
and for //2 you will not get any assert error as here (t>1) is true.