- Equals () method of java.lang.Object class compares whether two object references of this class are aliases of each other. True/False
True
Explanation: equals() method of java.lang.Object class compares whether two objects are same or aliases of each other, as its implementation compares the objects with(==) operator. Not to confuse. This equals () method is overridden in java.lang.String class to show different behavior by comparing the values of two strings not the references.
- Set, List and Map extend java.util.Collection interface. True/False?
False
Explanation: Set and list extend java.util.Collection interface, but Map does not.
- Java collections generally have the ability to extend to accommodate as many elements of objects as necessary. True/False.
True
Explanation: Collections in java can hold as many object references as the size of the collections can grow dynamically.
- Java collections can hold only references to objects not actual objects. True/False?
True
Explanation: Collections in java are container classes that hold the object references, not the actual objects.
- Dictionary is the abstract class that behaves similar to the interface____. A) Set B) List C) Map D) Collection
Map
Explanation: The Dictionary class is the abstract parent of any class, such as Hashtable, which maps keys to values. Every key and every value is an object. In any one Dictionary object, every key is associated with at most one value. Given a Dictionary and a key, the associated element can be looked up. Any non-null object can be used as a key and as a value. This class is obsolete now. New implementation should implement the map interface, rather than extending this class.
- equals() method of java.lang.String class compares whether two references are indication the same string object while the equality operator (= =) compares whether the value of two strings are same or not. True/False
False
Explanation: Quite the opposite; equals method of java.lang.String class compares whether the value of two strings are same or not; while (= =) whether two references are indication the same string object.
- Java collections can hold primitives values as well as object references. True/False.
False
Explanation: Collections in java can only hold object references not primitive values. But arrays in java can hold both primitive values and object references.
- hashCode() is a non-static methods of java.lang.Object class. True/False?
True
Explanation: Public int hashCode() resides in Object class; every java class inherits this method.
- hashCode() of java.lang.Object produces a hash code of type ___ for an object. A) String B) int C)double D)long
int
Explanation: hashCode() produces a hash code of type int for an object that is typically used as an offset from the start of the memory that has been allocated to that object.
10. which two of the following statements are true about List in java? A) A list id ordered but rejects duplicate values. B) A List is ordered and accepts duplicate values. C) A list has no special order but accepts duplicate values. D) A list has no special order and rejects duplicate values.
B
11 _____ method is used of java.lang.String to check equality between two string objects ignoring the case of the string characters (No extra space space, parentheses or arguments are required while typing the method name)
equalsIgnoreCase
12) There are three main types of collections in Java: Set, List and ___.
Map
No comments:
Post a Comment