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 DanChisholm's  assertion question 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 "DanChisholm Watch "DanChisholm New topic

DanChisholm's assertion question

naraharirao mocherla
Ranch Hand

Joined: Aug 16, 2005
Posts: 45
The answes for this question are b,c and e...

How come the answer b is corect?
When assertions disabled it prints nothing..(Is it b'coz it does not have any println statement in the method m1???

The method B is returning c right???

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Yes, there are no print statements anywhere, so nothing is ever printed unless there is an AssertionError.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Arvind Giri
Ranch Hand

Joined: Jun 26, 2005
Posts: 91
dear naraharirao,
if assertions are not enabled at run time then the code will be same as

see commented line.

class B {
int a, b, c;
private void setA(int i) {a = i;}
private void setB(int i) {b = i;}
private int m1 (int i) {
c = a + b + i;
//assert c < 200 : c;
return c;
public static void main (String[] args) {
B b = new B();

Hope this will help you

Regards<br /> <br />Arvind Giri<br />MCA,SCJP 1.4,SCWCD 1.4<br />Looking for SCDJWS
naraharirao mocherla
Ranch Hand

Joined: Aug 16, 2005
Posts: 45
Thank you very much for both of you ..
Arvind and Mark..


I agree. Here's the link:
subject: DanChisholm's assertion question
It's not a secret anymore!