aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assertion" Watch "Assertion" New topic
Author

Assertion

Tushar Gosalia
Greenhorn

Joined: Feb 19, 2013
Posts: 26
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: 103
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: 590
There are two arguments , file1 and file2.
Then a.length is 2 not 1. So, the assertion is false and return an error.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assertion
 
Similar Threads
Package question
Various examples of having errors thrown relative to the Error class
basic instantiation question
Windows File Paths
Compare Two Text Files