Deepika Srivastava

Greenhorn
+ Follow
since Jul 15, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Deepika Srivastava

bharat bhasin wrote:How is Comparable different from Comparator?
Also what how do we modify the instances of the class we implement Comparable in?
What do we do when we implement Comparator ?



The following table summarizes the differences between the Comparable and Comparator interfaces:

Comparable InterfaceComparator Interface
It uses the compareTo() method. <uc:stx>int objectOne.compareTo(objectTwo)</uc:stx>It uses the compare() method. <uc:stx>int compare(ObjOne, ObjTwo)</uc:stx>
It is necessary to modify the class whose instance is going to be sorted.A separate class can be created in order to sort the instances.
Only one sort sequence can be created. Many sort sequences can be created.
It is frequently used by the API classes.It it used by third-party classes to sort instances.
14 years ago

bharat bhasin wrote:How is Comparable different from Comparator?
Also what how do we modify the instances of the class we implement Comparable in?
What do we do when we implement Comparator ?



Hello, bharat

The following table summarizes the differences between the Comparable and Comparator interfaces:

Comparable Interface Comparator Interface

It uses the compareTo() method. It uses the compare() method.
int compare(ObjOne, ObjTwo) int objectOne.compareTo(objectTwo)

It is necessary to modify the class whose instance is A separate class can be created in order to sort instance
going to be sorted.

Only one sort sequence can be created. Many sort sequences can be created.

It is frequently used by the API classes. It it used by third-party classes to sort instances.
14 years ago

Rob Prime wrote:

Deepika Srivastava wrote:

Shruthi Sam wrote:Hi,
I know java doesn't support multiple inheritance directly and through the interface we can achieve multiple inheritance in java. And we know that all the classes extends the Object class by default. So if we are having a class say x. Let us assume that x extends another class say y. In this scenario x extends y and Object . Is that right? if that is the case is that not a multiple inheritance? Please clarify.



heelloooo


What is the meaning of this post? Is it a kick? If so, 14 minutes is much, much too early to warrant it. http://faq.javaranch.com/java/PatienceIsAVirtue



Hello Shruthi,

In this scenario, the class X extends the class Object i.e. it is the root of the class hierarchy and every class has Object as a superclass. Here, the class Y extends the class Oject. However, the class X is not extending both classes i.e. class Y and class Object at a same time, the class Object is the superclass of the class X but it is not the direct superclass of X. Hence it is not multiple inheritance.
14 years ago

Shruthi Sam wrote:Hi,
I know java doesn't support multiple inheritance directly and through the interface we can achieve multiple inheritance in java. And we know that all the classes extends the Object class by default. So if we are having a class say x. Let us assume that x extends another class say y. In this scenario x extends y and Object . Is that right? if that is the case is that not a multiple inheritance? Please clarify.



heelloooo
14 years ago