Question
class Test1
{
public int value;
public int hashCode() { return 42; }
}
class Test2
{
public int value;
public int hashcode() { return (int)(value^5); }
}
a.
class Test1 will not compile.
b.
The Test1 hashCode() method is more efficient than the Test2 hashCode() method.
c.
The Test1 hashCode() method is less efficient than the Test2 hashCode() method.
d.
class Test2 will not compile.
Posted under Java Programming
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. Which statement is true?
Similar Questions
Discover Related MCQs
Q. Which statement is true for the class java.util.HashSet?
View solution
Q. Which of the following statements about the hashcode() method are incorrect?
1. The value returned by hashcode() is used in some collection classes to help locate objects.
2. The hashcode() method is required to return a positive int value.
3. The hashcode() method in the String class is the one inherited from Object.
4. Two new empty String objects will produce identical hashcodes.
View solution
Q. What two statements are true about properly overridden hashCode() and equals() methods?
1. hashCode() doesn't have to be overridden if equals() is.
2. equals() doesn't have to be overridden if hashCode() is.
3. hashCode() can always return the same value, regardless of the object that invoked it.
4. equals() can be true even if it's comparing different objects.
View solution
Q. Which two statements are true about comparing two instances of the same class, given that the equals() and hashCode() methods have been properly overridden?
1. If the equals() method returns true, the hashCode() comparison == must return true.
2. If the equals() method returns false, the hashCode() comparison != must return true.
3. If the hashCode() comparison == returns true, the equals() method must return true.
4.If the hashCode() comparison == returns true, the equals() method might return true.
View solution
Q. Which of the following is smallest integer data type ?
View solution
Q. Which of the following is not a primitive data type ?
View solution
Q. Integer Data type does not include following primitive data type ____________.
View solution
Q. Which of the following data types comes under floating data types ?
View solution
Q. Which of the following values, cannot be stored using Character data type?
View solution
Q. Range of Byte Data Type is ____________.
View solution
Q. What is size of integer in Java Programming?
View solution
Q. Which of the following data type(s) can store 64 bit Value?
View solution
Q. Short data type has a minimum value of _____________.
View solution
Q. Default value of variable having boolean data type is ___________.
View solution
Q. Which of the following are legal lines of Java code?
1. int w = (int)888.8;
2. byte x = (byte)100L;
3. long y = (byte)100;
4. byte z = (byte)100L;
View solution
Q. Which of the following are legal lines of Java code?
1. int w = (int)888.8;
2. byte x = (byte)100L;
3. long y = (byte)100;
4. byte z = (byte)100L;
View solution
Q. Which of these coding types is used for data type characters in Java?
View solution
Q. Java array is a collection of ________.
View solution
Q. Array data access using _____.
View solution
Q. At time of array initialization which is necessary to specify?
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Java Programming? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!