adplus-dvertising

Welcome to the Data Types,Variables and Arrays MCQs Page

Dive deep into the fascinating world of Data Types,Variables and Arrays with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Data Types,Variables and Arrays, a crucial aspect of Java Programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Data Types,Variables and Arrays, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Java Programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Data Types,Variables and Arrays. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Java Programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Data Types,Variables and Arrays. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Data Types,Variables and Arrays MCQs | Page 15 of 32

Explore more Topics under Java Programming

Q141.
What will be the output of the program?

package foo; 
import java.util.Vector; /* Line 2 */
private class MyVector extends Vector 
{
    int i = 1; /* Line 5 */
    public MyVector() 
    { 
        i = 2; 
    } 
} 
public class MyNewVector extends MyVector 
{
    public MyNewVector () 
    { 
        i = 4; /* Line 15 */
    } 
    public static void main (String args []) 
    { 
        MyVector v = new MyNewVector(); /* Line 19 */
    } 
}
Discuss
Answer: (b).Compilation will fail at line 3.
Q142.
What will be the output of the program?

public class Test 
{ 
    private static int[] x; 
    public static void main(String[] args) 
    { 
        System.out.println(x[0]); 
    } 
}
Discuss
Answer: (d).NullPointerException at runtime
Q143.
What will be the output of the program?

import java.util.*; 
class I 
{
    public static void main (String[] args) 
    {
        Object i = new ArrayList().iterator(); 
        System.out.print((i instanceof List)+","); 
        System.out.print((i instanceof Iterator)+","); 
        System.out.print(i instanceof ListIterator); 
    } 
}
Discuss
Answer: (c).Prints: false, true, false
Q144.
Assuming that the equals() and hashCode() methods are properly implemented, if the output is "x = 1111", which of the following statements will always be true?
x = 0;
if (x1.hashCode() != x2.hashCode() )  x = x + 1;
if (x3.equals(x4) )  x = x + 10;
if (!x5.equals(x6) ) x = x + 100;
if (x7.hashCode() == x8.hashCode() )  x = x + 1000;
System.out.println("x = " + x);
Discuss
Answer: (b).x3.hashCode() == x4.hashCode()
Q145.
Which of the following are true statements?

1. The Iterator interface declares only three methods: hasNext, next and remove.
2. The ListIterator interface extends both the List and Iterator interfaces.
3. The ListIterator interface provides forward and backward iteration capabilities.
4. The ListIterator interface provides the ability to modify the List during iteration.
5.The ListIterator interface provides the ability to determine its position in the List.
Discuss
Answer: (b).1, 3, 4 and 5
Discuss
Answer: (a).The elements in the collection are ordered.
Q147.
Which statement is true?
class Test1 
{
    public int value;
    public int hashCode() { return 42; }
}
class Test2 
{
    public int value;
    public int hashcode() { return (int)(value^5); }
}
Discuss
Answer: (c).The Test1 hashCode() method is less efficient than the Test2 hashCode() method.
Discuss
Answer: (c).The elements in the collection are guaranteed to be unique.
Q149.
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.
Discuss
Answer: (b).2 and 3
Q150.
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.
Discuss
Answer: (c).3 and 4

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!