• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assertion

 
Tushar Gosalia
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1322
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two arguments , file1 and file2.
Then a.length is 2 not 1. So, the assertion is false and return an error.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic