×

Multiple-Choice Questions

Web Technologies MCQs

Computer Science Subjects MCQs

Databases MCQs

Programming MCQs

Testing Software MCQs

Digital Marketing Subjects MCQs

Cloud Computing Softwares MCQs

AI/ML Subjects MCQs

Engineering Subjects MCQs

Office Related Programs MCQs

Management MCQs

More

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);
  }
}
  1. {10 =Java, 3 =C, 4 =C++, 6 =null, 5 =Ruby}
  2. {10 =Java, 6 =null, 5 =Ruby, 4 =C++, 3 =C}
  3. {3 =C, 4 =C++, 5 =Ruby, 6 =null, 10 =Java}
  4. None of these

Answer: B) {10 =Java, 6 =null, 5 =Ruby, 4 =C++, 3 =C}

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.