Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DanChisholm's assertion question

 
naraharirao mocherla
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, there are no print statements anywhere, so nothing is ever printed unless there is an AssertionError.

Mark
 
Arvind Giri
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
naraharirao mocherla
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for both of you ..
Arvind and Mark..

Regards

Narahari..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic