• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java questions,give answers

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer those tricky questions!
 
Nilushika Udayangani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.
You can start off by answering this quickly first QuoteYourSources (<= click link)
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 1044
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic