Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A  question on assert statement from mock exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A  question on assert statement from mock exam" Watch "A  question on assert statement from mock exam" New topic
Author

A question on assert statement from mock exam

pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi to all

The source of this is K& B master Exam.

Which of the following statements is true?(Choose all that apply)
A. In an assert statement ,the expression after the colon ( can be any Java expression.
B. If a switch block has no default ,adding an assert default is considered appropriate.
C. In an assert statement,if the expression after the colon( does not have a value ,the assert's error message will be empty.
D It is appropriate to handle assertion failures using a catch clause.


The answer is given is B.Can anybody show me a short program which shows /follows the B statement?


I have tried ,but could not use it proper .Below is my code.


package FlowControl;

public class Switch1{

public static void main(String[] args){
int x = 5;

switch(x){
case 2: break;
// default: System.out.println("default");break;
case 7: System.out.println("5");

assert default:5;

}

}

}


SCJP 5.0(75%), SCWCD 5.0(88%)
Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
You can try in the following way:



Output:



Hope that helps,

Regards,
Gitesh
[ January 16, 2008: Message edited by: Gitesh Ramchandani ]
Vishwanath Krishnamurthi
Ranch Hand

Joined: Jun 04, 2007
Posts: 331
Hi,

Did you copy that option correctly...?? Its not all that clear..

Well, anws, consider the code below:
(this is allowed, and appropriate too)


Regards,
Vishwa


Blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A question on assert statement from mock exam
 
Similar Threads
assertions
assertion
AssertionError
inappropriate use of assertions
Use of Assert in Java