aspose file tools*
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
Author

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
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
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();
b.setA(50);
b.setB(100);
b.m1(50);
}}


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..

Regards

Narahari..
 
 
subject: DanChisholm's assertion question