File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

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;

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:


Hope that helps,

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

Joined: Jun 04, 2007
Posts: 331

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

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


I agree. Here's the link:
subject: A question on assert statement from mock exam
It's not a secret anymore!