Quizzes
Site Language: English
Українська
English
Русский
Programming Tests
Login
Sign Up
Programming Tests
Theory
Snippets
Papers
Landing
Android
Prices
FAQ
Cosmo Story
Terms and Conditions
Privacy Policy
Cookies Policy
Send Feedback
hashCode
:
Content language: English
Русский
What is the result of the following code execution? Integer i = 5000; System.out.println(i.hashCode());
hashcode
Select all correct statements regarding the concept of relationship between hashCode() and equals(Object o) methods
hashcode
In accordance with the contract, the hashCode() method should return the same integer value for two objects that are equal according to the equals() method. Is that true?
hashcode
What will happen as a result of the following code? class A {} class B extends A {} public class Test { static public void main(String args[]) { B b = new B(); A a = b; if (a.hashCode() == b.hashCode()) System.out.print("Passed"); } }
hashcode
Which java.util.Set realizations sorts the elements by their natural order (or on Comparator basis).?
hashcode
Consider the following code: import java.util.*; class MyDataStore { public static void main(String [] args) { // Put the code structure.put("a", 420); System.out.println(structure.get("a")); } } Which from the mentioned options can be inserted into the line 4 (independently) for class to successfully compile and run?
hashcode
What will be the result of the following code execution? import java.util.*; class Employee { private String name; public Employee(String name) { this.name = name; } public String toString() { return name; } public boolean equals(Object obj) { HashCodeTest.count++; if (obj == null) return false; if (obj.getClass() != getClass()) return false; Employee emp = (Employee) obj; if (this.name == emp.name) { return true; } return false; } public int hashCode(){ return name.hashCode(); } } public class HashCodeTest { static int count = 0; public static void main(String[] args) { Map employees = new HashMap(); employees.put(new Employee("Joe"), new Integer("1")); employees.put(new Employee("Chandler"), new Integer("2")); employees.put(new Employee("Chandler"), new Integer("2")); employees.put(new Employee("Ross"), new Integer("3")); Iterator iterator = employees.keySet().iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } System.out.println(count); } } P.S. For experts - hashtags of the lines "Joe", "Chandler" and "Ross" are different.
hashcode
What will the given hashMap contain, after the below code is compiled and run? public static void main(String[] args) { HashMap hashMap = new HashMap(); List list = new ArrayList(); list.add(hashMap); hashMap.put(list, null); hashMap.put(list, null); }
hashcode
What will be printed after execution of this code? class User { private String name; public User( String name ) { this.name = name; } public boolean equals( Object obj ) { User user = (User) obj; return user.name.equals( name ); } public String toString() { return name; } } class Foo { public static void main(String...arguments) { //1 User user1 = new User( "John" ); User user2 = new User( "Bill" ); User user3 = new User( "John" ); Set<User> userSet = new HashSet<User>(); userSet.add( user1 ); userSet.add( user2 ); userSet.add( user3 ); //2 System.out.println( "Count of users: " + userSet.size() ); //3 } }
hashcode
case class Key(x: Int, var y: Int) val key = Key(1,2) val someMap = Map(key -> (1,2)) val newKey = key newKey.y = 3 val newMap = someMap + (newKey -> (1,3)) println(newMap(key)) What will be printed into the console?
hashCode
← Prev
1
2
Next →
Sign Up Now
or
Subscribe for future quizzes