• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

DanChisholm's assertion question

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???

 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, there are no print statements anywhere, so nothing is ever printed unless there is an AssertionError.

Mark
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for both of you ..
Arvind and Mark..

Regards

Narahari..
 
This tiny ad will self destruct in five seconds.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic