aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes dan exam doubt 12 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "dan exam doubt 12" Watch "dan exam doubt 12" New topic
Author

dan exam doubt 12

amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
hi

in one question


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);
}}

Which statements are true?

a. If assertions are enabled at run time it prints an error message.
b. With assertions enabled it prints nothing.
c. With assertions disabled it prints an error message.
d. With assertions disabled it prints 1112.
e. With assertions disabled it prints nothing.
f. The assert statements are being used to check a precondition--something that must be true when the method is invoked.
g. Method m1 is an example of an improper use of an assert statement: an assert statement should not be used for argument checking in a non-public method.
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.



---------
the answer were a,d,f,h

in this...y With assertions disabled it prints 1112.
and y not With assertions disabled it prints an error message i.e "c" option ?
but when if it is dissable...how complier treat the word assert in code ?
if it is not declared as identifier.. in above too..its not identifier....w.r.t. diablity of assertion

pls explain

thanx


Thanks and Regards, Amit Taneja
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
a. If assertions are enabled at run time it prints an error message.

I think the key here is that the question is asking about assertions being enabled / disabled at runtime. Perhaps your are thinking of compile-time enabling without the -source 1.4.

If assertions aren't enable at compile time then you'd get a boatload of errors.
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
good point carol

but are u sure that they are asking about runtime enable/disable of assertion ??


anyway,, Thanx a ton


Amit
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
I am, but obviously you are not (sure that they are asking about runtime enable/disable of assertion).

1. See Compiling with assertions vs. Enabling and Disabling Assertions.

2. The answers given in your original post match the behavior for runtime enabling/disabling (did you try to compile and run these?) .

3. Try a google search and see what you get when you search for enabling assertions. e.g.

From Enabling Assertions from the command-line:

e104. Enabling Assertions from the Command Line
The command line options -ea and -da allow you to enable and disable assertion in a package subtree or in a class. Here are several examples of the switches. Enable assertions in all non-system classes:
java -ea MyApp


Enable assertions in all classes in the unnamed package:
java -ea:... MyApp


Enable assertions in all classes in a package subtree:
java -ea:com.mycompany... MyApp


Enable assertions in a particular class:
java -ea:com.mycompany.MyCompany MyApp


Disable assertions in all classes in a package subtree:
java -da:com.mycompany... MyApp


Disable assertions in a particular class:
java -da:com.mycompany.MyClass MyApp


Multiple assertion switches on the command line are processed from left to right. Enable assertions in all classes in a package subtree except for one class:
java -ea:com.mycompany... -da:com.mycompany.MyClass MyApp


[ February 24, 2005: Message edited by: Carol Enderlin ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dan exam doubt 12