• Post Reply Bookmark Topic Watch Topic
  • New Topic

java questions,give answers  RSS feed

 
Nilushika Udayangani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer those tricky questions!
 
Nilushika Udayangani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the answer for following question,Can you explain it?

What will be occured?
1.compilation fails at Line A because all the elements must implement the Comparable interface, but animal element hasn't.
2.compilation fails at Line B because Cartoon element hasn't implements the Comparable interface
3.multiple compile errors
4.sorts fine because String & Integer classes have implemented Comparable interface
5.non of above
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.
You can start off by answering this quickly first QuoteYourSources (<= click link)
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:You can start off by answering this quickly first...

@Nilushika: We also like you to ShowSomeEffort (←click); so why don't you tell us first what you think the answer is, and why?

If you're wrong, we can help guide you to the right one; but we don't like to just hand out answers here.

Winston
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A naive question: did you give it a try?
 
Nilushika Udayangani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I am a student for OCPJP . When I was going through the "sorting of arraylists" I made that question covering important facts on that theory part. So I just wanted to see how other students answer that. I misunderstanded that this java forum also allow us to perform our own made questions and allow others to answer it . Can I know is there any other feature here, to post our own made questions?


The answer for above question is 5.
If you want I can give the explanation also.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nilushika Udayangani wrote:Sorry I am a student for OCPJP . When I was going through the "sorting of arraylists" I made that question covering important facts on that theory part. So I just wanted to see how other students answer that. I misunderstanded that this java forum also allow us to perform our own made questions and allow others to answer it . Can I know is there any other feature here, to post our own made questions?

Well, if it is genuinely a question made up by you, you could post it in the "Programming Diversions" forum, but you might want to use a better subject line.
And if you do so, make sure it IS made up by you, because plagiarism will be "outed" .

The answer for above question is 5.
If you want I can give the explanation also.

Sure. That would be good.

Winston
 
Tim Cooke
Marshal
Posts: 4039
239
Clojure IntelliJ IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaRanch is a place where folks can come to get top rate assistance with learning all things Java. I think your misunderstanding is that you think we are here to answer questions just for the sake of it. I can only speak for myself here but I have no motivation to answer questions where the OP has made no effort to work out the solution for themselves. This is not Quiz Time.

You might get more traction with these types of questions over at StackOverflow, which is a Q&A site. Folks fall over themselves to be the first to post the right answer over there.

However, if you are looking to learn and are willing to put the work in then this is the place for you. To get the most out of The Ranch, have a read through HowToAskQuestionsOnJavaRanch. The better the question, the more likely you are to get valuable answers.
 
Nilushika Udayangani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you.
This is not a type-safe ArrayList. Let's consider the answer A: animal element (and Cartoontype element) hasn't implements the comparable Interface.But there compilation get success, because this is not an Animal type safe Arraylist.If only this is Animal type safe ArrayList there compilation get failes because Animal elements doesn't bear its sort sequence.
But in this ArrayList we have String and Integer Objects also and they have already implemented with comparable Interface.So when coming to sorting this arraylist at the run time only an Exception comes because elements are not mutually comparable. So the 4th answer is also wrong because sorting fails as ClassCastException. 3rd is also wrong code compiles non of errors. answer is 5
 
Nilushika Udayangani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:JavaRanch is a place where folks can come to get top rate assistance with learning all things Java. I think your misunderstanding is that you think we are here to answer questions just for the sake of it. I can only speak for myself here but I have no motivation to answer questions where the OP has made no effort to work out the solution for themselves. This is not Quiz Time.

You might get more traction with these types of questions over at StackOverflow, which is a Q&A site. Folks fall over themselves to be the first to post the right answer over there.

However, if you are looking to learn and are willing to put the work in then this is the place for you. To get the most out of The Ranch, have a read through HowToAskQuestionsOnJavaRanch. The better the question, the more likely you are to get valuable answers.




Thank you Tim Cooke for your directions.
 
Nilushika Udayangani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you.
This is not a type-safe ArrayList. Let's consider the answer A: animal element (and Cartoontype element) hasn't implements the comparable Interface.But there compilation get success, because this is not an Animal type safe Arraylist.If only this is Animal type safe ArrayList there compilation get failes because Animal elements doesn't bear its sort sequence.
But in this ArrayList we have String and Integer Objects also and they have already implemented with comparable Interface.So when coming to sorting this arraylist at the run time only an Exception comes because elements are not mutually comparable. So the 4th answer is also wrong because sorting fails as ClassCastException. 3rd is also wrong code compiles non of errors. answer is 5
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!