This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Drag n Drop Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Drag n Drop Question" Watch "Drag n Drop Question" New topic
Author

Drag n Drop Question

Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
Hi,
This was a question from whizlabs:
The Bold words are what i have filled in the code


This code Compiles fine and output is sorted by name and age of employees.

At the line where i have marked 1 instead of :
public int compare(T obj1, T obj2)//1
I made it
public int compare(Employee obj1, Employee obj2)//1

That means i used Employee instead of T.
The output of both the programs is same
I wanted to konw that is it wrong to do this in the exam?


Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Sara Olsen
Ranch Hand

Joined: Oct 12, 2005
Posts: 59
This does not compile:
public int compare(Employee obj1, Employee obj2)//1

My compiler says:
The type MyComparator<T> must implement the inherited abstract method Comparator<T>.compare(T,T).
Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
Sara,

public int compare(Employee obj1, Employee obj2)//1
It compiles fine in JDK 1.5 and the output is :
------------------
Daisy of age 22
Daisy of age 40
George of age 29
Jacob of age 30
-----------------=
Sara Olsen
Ranch Hand

Joined: Oct 12, 2005
Posts: 59
Ok strange, cause I pasted your code in Eclipse, and compiled it with version 1.5 and it does not compile:-)
Hein Behrens
Greenhorn

Joined: Oct 13, 2005
Posts: 2
Works here textpad and Java 1.5

Compiles and runs both versions
Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
But yet nobody answered me...??
 
wood burning stoves
 
subject: Drag n Drop Question
 
Similar Threads
i have not override comparator's equals() method(overrided compare())-working fine-how?
list files names a litle "counting" problem
how comparator works?
Generics Compiler error
Sorting through Comparable(Very Urgent)