aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertion : Dan's mock question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assertion : Dan Watch "Assertion : Dan New topic
Author

Assertion : Dan's mock question

Shubh Bhat
Ranch Hand

Joined: Sep 08, 2002
Posts: 32
class A {
private void m1 (int i) {
assert i < 10 : i;
System.out.print(i);
}
public void m2 (int i) {
assert i < 10 : i;
System.out.print(i);
}
public static void main (String[] args) {
A a = new A();
a.m1(11);
a.m2(12);
}
}

two of the answers are:
a. If assertions are not enabled at run time it prints an error message.
b.With assertions disabled it prints "1112"
what is the difference between. assertion not enabled and assertion disabled??
please explain. Thanks


~-<br />Doing my best this time and everytime.<br />-- Me
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Assertions can be disabled at compile time and at run time. The details are available in the document titled "Programming with Assertions".


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
My assertions exam has not yet been added to my main exam page. Instead, it is still a separate beta exam.
I see that the assertions exam has had 147 hits. I'm wondering how people feel about it. Was it too easy, too difficult, or just about right?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Actually option b) is:
b. If assertions are not enabled at run time it prints "1112".
Dan, I know it's 4am here and I should be sleeping, but why do you say the above code example gives an error when assertions are disabled at runtime(case a)? The answer to Q9 says a) is true.
I compiled it with -source 1.4 and did not enable
assertions at run time. It printed 1112. So b) is the true one.
-Barry
[ September 22, 2002: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Shubh Bhat
Ranch Hand

Joined: Sep 08, 2002
Posts: 32
Exactly Barry that was my question.
Dan the questions are interesting, not to tough neither too easy, I think. I would only know how much it is closer to the real stuff, on wed. that's when I plan to take the exam 1.4.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
O.K. Now I understand that you are asking why I gave two obviously contradictory answers on the assertions exam. I initially read your question too quickly and thought that you were asking how assertions are enabled. I'm sorry.
I just uploaded the correction. The answers are now as follows.
  • a. If assertions are enabled at run time it prints an error message.
  • d. With assertions disabled it prints "1112".
  • f. The assert statements are being used to check a precondition--something that must be true when the method is invoked.
  • h. Method m2 is an example of an improper use of an assert statement: an assert statement should not be used for argument checking in a public method.
  •  
    wood burning stoves
     
    subject: Assertion : Dan's mock question