This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

My problem wif Java questionssss

 
Nicky Eng
Ranch Hand
Posts: 378
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so according to you 0 is greater than 0? Interesting mathematics.
 
soumya ravindranath
Ranch Hand
Posts: 300
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 232
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 300
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 378
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 378
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 378
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your explanation...
 
Swapna Anand
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 378
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deleted second question because it is a real exam question.
[ July 02, 2005: Message edited by: Barry Gaunt ]
 
Nicky Eng
Ranch Hand
Posts: 378
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh sorry, mod.

thanks for doing that too.

all the best.
cheers
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic