Question

2. What is the difference between MyClass implements Comparable and MyClass mplements Comparable<MyClass>? 3. When using geneJava

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 2:
MyClass implements Comparable means we are writing to a custom comparator which is not specific to any object, so we receive the parameters as Object for the compare method
MyClass implements Comparable<MyClass> we are writing the comparator to specific to a particular class which will not work other classes. if we write like this than at runtime we will not get any class cast exceptions as it is bounded to once class only


Answer 3:
if we are extending the comparable interface to any other interface than we use they keyword extends

second anytype indicates the what type we are handling like for which class we are writing the comparator

Note : If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Java 2. What is the difference between MyClass implements Comparable and MyClass mplements Comparable<MyClass>? 3. When...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the ...

    Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...

  • Java. Must not use Java API java.util.Stack /** A class of stacks whose entries are stored...

    Java. Must not use Java API java.util.Stack /** A class of stacks whose entries are stored in an array. Implement all methods in ArrayStack class using resizable array strategy, i.e. usedoubleArray() Must throw StackException during exception events in methods:    peek(), pop(), ArrayStack(int initialCapacity) Do not change or add data fields Do not add new methods */ import java.util.Arrays; public class Arraystack«Т> implements Stack!nterface«T> private TI stack;// Array of stack entries private int topIndex; /7 Index of top entry private...

  • I need help solving for step responses; What is the difference between a step response and...

    I need help solving for step responses; What is the difference between a step response and a natural response? And how would I go about solving these circuits? If possible write out the steps, and please do not round Thanks 23 k22 t=0 + 6 V 30 kN2 3 0 + 22uF For the circuit shown above, find the capacitor voltage for t> (i.e after the switch closes). The solution, since this a "step" response, should be of the form...

  • question 27’s end is in the next page 24 Suppose you have created a list using the statement ArrayList String> NYIT CS Courses new ArrayList(31 What would java do when you try to insert more...

    question 27’s end is in the next page 24 Suppose you have created a list using the statement ArrayList String> NYIT CS Courses new ArrayList(31 What would java do when you try to insert more than 31 courses? ANS: LinelI) check one with x: continue process as usual I Ijava automatically expand array space you manually expand more array spaces 25 Suppose NYIT CS COurscs is an object of the class Array List Suring Write Java statements that will display...

  • 1 What is a difference between override and new when it comes to inheritance? 2 What...

    1 What is a difference between override and new when it comes to inheritance? 2 What is the difference between List<type> and ArrayList? AND Which one should you use and why? 3. If I have a file test.txt, and have committed it to the git repository using: $ git commit test.txt Then made some changes, what command (or option) do you use to get the original file back (ie restore the contents of the committed file)? 4 What command (or...

  • 14. What is the difference between generation time and the rate of population growth? 15. When...

    14. What is the difference between generation time and the rate of population growth? 15. When using the logistic population growth model, what are the different causes of slow population growth at low population sizes versus high population sizes? 8. What are the patterns of survival with age in the three types of survivorship curves? 9. How would you describe the generation time of a population? 10. Given that white tailed deer give birth to fawns each spring, which population...

  • Problem 8 In class, we discussed the difference between a pure (or effect-free) function (i.e. one...

    Problem 8 In class, we discussed the difference between a pure (or effect-free) function (i.e. one that returns a value, but does not produce an effect) and a mutating function i.e one that changes the value of its parameters). In this exercise, we ask you to demonstrate your understanding o this distinction by implementing the same functionality as both a pure function, and as a mutating function. Both functions take a list of int as a parameter. The pure variant...

  • Question 1 of 3 < > 0.5/1 E On October 2, 2020, Teal Company sold $5,510...

    Question 1 of 3 < > 0.5/1 E On October 2, 2020, Teal Company sold $5,510 of its elite camping gear (with a cost of $3,470) to Lynch Outfitters. As part of the sales agreement, Teal includes a provision that if Lynch is dissatisfied with the product, Teal will grant an allowance on the sales price or agree to take the product back (although returns are rare given the long-term relationship between Teal and Lynch). Teal expects total allowances to...

  • In c++ please and a correct answer please because last time some guy gave me a...

    In c++ please and a correct answer please because last time some guy gave me a wrong code. Thanks Part 1 - Simple Classes and Class Variables 1-1 Define and implement a class named animal that has the following public constructors and behaviours animal (string aSpecies); // animals are allocated a unique ID on creation, // the first animal has ID 1, the second animal is 2 and so on void set_name(string aName); // change the animal's name string get_speciesO;...

  • SOLUTION SET UP The center of curvature of the first surface of the lens is on...

    SOLUTION SET UP The center of curvature of the first surface of the lens is on the outgoing side, so R = +6.0 mm. The center of curvature for the second surface is not on the outgoing side, so R2-_5.5 mn. We solve for f and then use the result in the thin-lens equation. Now we'll apply the thin-lens equation to the eye When light enters your eye, most of the focusing happens at the interface between the air and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT