• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Assertion again.

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all ,
another one from javacertificate.com
Which of the following statements will compile AssertTest.java to use assertions?


1 javac -ea AssertTest.java
2 javac -enableassertions AssertTest.java
3 javac AssertTest.java
4 javac -source 1.4 AssertTest.java

Answer given is 4. why is it so ??
TIA.
 
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vishy Karl:
Hi all ,
another one from javacertificate.com
Which of the following statements will compile AssertTest.java to use assertions?


1 javac -ea AssertTest.java
2 javac -enableassertions AssertTest.java
3 javac AssertTest.java
4 javac -source 1.4 AssertTest.java

Answer given is 4. why is it so ??
TIA.


Assertions where added in Java 1.4. If you compile with
the option Java 1.3, assertions won't be considered at
all and you can even use the word assert as a method name
for example.
In order to 'activate' assertions during run-time you will
have to use the flag -ea. But of course this is only possible
if you compiled with the Java 1.4 option.
Greetings,
Gian Franco
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vishy Karl:
Answer given is 4. why is it so ??


Because that's the way it is. 'source' is used to provide compatibilty with the specific release (in your case 1.4)
The first two are used with the 'java' command not 'javac', it is used to enable assertion at runtime.
The third one is used to compile a normal source file that does not contain the 'assert' keyword.
 
BWA HA HA HA HA HA HA! Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic