A

Admin • 828.03K Points
Coach

Q. What will be the output of following Java code?

Code:
import java.util.Hashtable;

public class HashTableClass {
int hashcode;
HashTableClass(int hashcode) {
this.hashcode = hashcode;
}
public int hashCode() {
return hashcode;
}
public String toString() {
return hashcode + " ";
}

public static void main(String[] args) {
Hashtable ht = new Hashtable();

ht.put(new HashTableClass(10), "Java");
ht.put(new HashTableClass(3), "C");
ht.put(new HashTableClass(4), "C++");
ht.put(new HashTableClass(5), "Ruby");
ht.put(new HashTableClass(6), "null");

System.out.println(ht);
}
}
  • (A) {10 =Java, 3 =C, 4 =C++, 6 =null, 5 =Ruby}
  • (B) {10 =Java, 6 =null, 5 =Ruby, 4 =C++, 3 =C}
  • (C) {3 =C, 4 =C++, 5 =Ruby, 6 =null, 10 =Java}
  • (D) None of these
  • Correct Answer - Option(B)
  • Views: 8
  • Filed under category Java
  • Hashtags:

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.