File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question on assert statement from mock exam

 
pradeep singh
Ranch Hand
Posts: 339
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;

}

}

}
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 331
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic