thanks for view my post...i will have some question these day, so i plan to create this topic for everyone here give me some comment about the question i will be posting.
this first question is :
What is the result?
A. finished B. compilations fails C. an assertionError is thrown D. An AssertionError is thrown and finished is output.
explanation provided. answer : A This question is a bit tricky because it lacks the following information: it should include a
statement that says whether or not assertions are enabled. if they are indeed enabled, the correction
answer is C. but if they are not, the correct answer is A. Assertion are not enabled by default so if the
question is not changed, the most locgical answer is A. ---------------
i against the answer provided. My answer would be B. why? because if assertion not enabled, then "assert <x>0): "assertion failed"; " will give a compilation fails. i had run the code to test it and it shows i'm right about answer B. the question is tricky yes, but does not means assertion not enabled, then "finished" will be the output !!! am i right? if the assertions are enabled, then answer C, yes, will be the true answer.
i wanna know anyone here could give me the comment or different answer?
thanks in advance
Diploma in Computer Studies
Formula 1 app by Maxis (Playbook)
As someone who has not worked with assertions, I too would argue that way. If the code given above is compiled without enabling assertions, it surely fails to compile OR does the author simply mean that we ignore the line with assertion and imagine it is compiled ? What are we missing ?
Originally posted by Jeroen Wenting: so according to you 0 is greater than 0? Interesting mathematics.
Joroen, read the question "n" number of times. n is until you understand the question.
Nicky, javac source 1.4 Test.java - this has to be used while compiling a source code when assertions is enabled. java -ea Test or java -enableassertions Test are used when running the compiled class with assertions enabled. They are NOT valid when the class has to be compiled.
This is from the javadocs of Sun. Unless you specifically request source mode 1.4 with the -source 1.4 flag, the compiler operates in source mode 1.3. If you forget to use this this flag, programs that use the new assert statement will not compile. Assertions are disabled by default.
Check the question properly again to see if any hint is given for compiling with assertions or running with assertion flag.
Joined: Jan 26, 2001
Exactly! I have come across a similar question in the past and was puzzled. Whenever there is no mention of "with assertion enabled" in the question, the correct answer should be "compilation fails", according to me.
I like your analysis. Information like whether the assertions are enabled or not should be given in the question, otherwise it is open to interpretation.
Joyce [ June 30, 2005: Message edited by: Joyce Lee ]
Joined: Mar 26, 2005
thanks all seniors....
my question was typed correctly perfectly....
in conclusion, my answer of B: compilations fail.
Answer A: finished.....this answer wont be correct for above question regardless of assertion enabled or not enabled. because when the expression of assert WONT be true( 0 > 0 is false) and "finished" wont be printed. Assert expression IS false and assertionError will be thrown BUT the above question is regardless of assertion enabled or not enabled.
Answer B: compilation fails.....this answer is correct due the question didn't mention about assertion enabled or not enabled.
Answer C: An Assertion is thrown.....this answer would be correct only if the Assertions are enabled and ( 0 > 0 ) give a false, "assertion failed" expression will be displayed. ------- I do konw about assertion already, i just dont quite understand the question, that's why i post it here. But thanks anyway for the explanation of assertion.
this question is clear, to me now. wait for my next post of question
Joined: Mar 26, 2005
second question i facing right now.
Real question deleted
I wonder why the answer given to me is C. state your answer and explanation why you pick that answer. thanks.
[ June 30, 2005: Message edited by: Nicky Eng ] [ July 02, 2005: Message edited by: Barry Gaunt ]
Originally posted by Nicky Eng: I wonder why the answer given to me is C. state your answer and explanation why you pick that answer.
Right answer is D because there are no no-arguments constructors in class Super. So, there are two solutions to compile without errors: create no-arg constructor in class Super or explicitly call super(text) in class Sub.