This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Drag n Drop Question  RSS feed

 
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 340
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok strange, cause I pasted your code in Eclipse, and compiled it with version 1.5 and it does not compile:-)
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works here textpad and Java 1.5

Compiles and runs both versions
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But yet nobody answered me...??
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!