Home »
MCQs »
Java MCQs
What will be the output of following Java code (7)?
87. What will be the output of following Java 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);
}
}
- {10 =Java, 3 =C, 4 =C++, 6 =null, 5 =Ruby}
- {10 =Java, 6 =null, 5 =Ruby, 4 =C++, 3 =C}
- {3 =C, 4 =C++, 5 =Ruby, 6 =null, 10 =Java}
- None of these
Answer: B) {10 =Java, 6 =null, 5 =Ruby, 4 =C++, 3 =C}