aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes My problem wif Java questionssss 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 "My problem wif Java questionssss" Watch "My problem wif Java questionssss" New topic
Author

My problem wif Java questionssss

Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
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


From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
so according to you 0 is greater than 0? Interesting mathematics.


42
soumya ravindranath
Ranch Hand

Joined: Jan 26, 2001
Posts: 300
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 ?
Sripathi Krishnamurthy
Ranch Hand

Joined: Mar 07, 2005
Posts: 232
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.
soumya ravindranath
Ranch Hand

Joined: Jan 26, 2001
Posts: 300
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.
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hi Nicky,

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 ]
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
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
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
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 ]
Roman Tomach
Greenhorn

Joined: Mar 17, 2005
Posts: 15
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.
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
thanks for your explanation...
Swapna Anand
Greenhorn

Joined: May 11, 2005
Posts: 7
The correct answer will be D as the implicit call to super is not defined

real exam code deleted
[ July 02, 2005: Message edited by: Barry Gaunt ]
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
hi guys......

i passed scjp 1.4 today. thanks to all those who helped.....the second question i posted here, came out in the real exam

all the best to all.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Deleted second question because it is a real exam question.
[ July 02, 2005: 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.
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
oh sorry, mod.

thanks for doing that too.

all the best.
cheers
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: My problem wif Java questionssss
 
Similar Threads
Assertions mock exam question
on assertions
Assertion enable or not?
assert help
Assertion