• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Enabling Assertions

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What should be the o/p:
public class Test {
public static void main(String[] args) {
int x = 0;
assert (x > 0): �assertion failed�;
System.out.println(�finished�);
}
}
Ans: Assertion thrown,or "finished".
If nothing is mentioned should we consider Assertion is disabled.
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For java 1.5, I found assertions are disabled at run-time. You have to use switch '-ea' to enable assertions at run-time.

But at compile time, the assertions is treated as a keyword by default.
 
Arnab Saha
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to know that if during Test of SCJP 1.4 if nothing is mentioned
what should we consider - Assertions enabled or Disabled.
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Disabled. They are only enabled if explicitly mentioned.
 
reply
    Bookmark Topic Watch Topic
  • New Topic