| Author |
Assertion
|
Tushar Gosalia
Greenhorn
Joined: Feb 19, 2013
Posts: 7
|
|
In the below given snippet what is file1 and file2??
public class test {
public static void main(String [] a) {
assert a.length == 1;
}
}
Which two will produce an AssertionError? (Choose two.)
A. java test
B. java -ea test
C. java test file1
D. java -ea test file1
E. java -ea test file1 file2 //why this is the answer
F. java -ea:test test file1
Ans:B,E
|
 |
vishal mishra
Ranch Hand
Joined: Jul 12, 2010
Posts: 79
|
|
Tushar Gosalia wrote:In the below given snippet what is file1 and file2??
public class test {
public static void main(String [] a) {
assert a.length == 1;
}
}
Which two will produce an AssertionError? (Choose two.)
A. java test
B. java -ea test
C. java test file1
D. java -ea test file1
E. java -ea test file1 file2 //why this is the answer
F. java -ea:test test file1
Ans:B,E
Assertions are disabled by default
Therefore B is correct.
E is also correct because in above code assertion is testing length of array 'a' .
|
 |
Zhenyi Luo
Ranch Hand
Joined: Sep 03, 2012
Posts: 33
|
|
Tushar Gosalia wrote:In the below given snippet what is file1 and file2??
public class test {
public static void main(String [] a) {
assert a.length == 1;
}
}
Which two will produce an AssertionError? (Choose two.)
A. java test
B. java -ea test
C. java test file1
D. java -ea test file1
E. java -ea test file1 file2 //why this is the answer
F. java -ea:test test file1
Ans:B,E
file1 and file2 are the arguments of String[] a, for E, a[0] = "file1", a[1] = "file2"
|
 |
Himai Minh
Ranch Hand
Joined: Jul 29, 2012
Posts: 292
|
|
There are two arguments , file1 and file2.
Then a.length is 2 not 1. So, the assertion is false and return an error.
|
 |
 |
|
|
subject: Assertion
|
|
|