☕ Java MCQ Questions – Page 42

Questions 821–840 of 3994 total — Java interview practice

▶ Practice All Java Questions
Q821 hard code error
What compile-time error will occur when compiling this Java code snippet?
java
public class Test {
    public static void main(String[] args) {
        int[][][] threeDArray = new int[2][][];
        threeDArray[0] = new int[3][];
        int[] oneD = new int[]{1, 2, 3};
        threeDArray[0][0] = oneD;
        System.out.println(threeDArray[0][0][0]);
    }
}
Q822 medium
What is the fundamental difference between `FileReader` and `FileInputStream`?
Q823 easy code output
What is the output of this code?
java
public class Main {
    public static void main(String[] args) {
        int[][] data = {{10, 20, 30}, {40, 50}};
        System.out.println(data.length);
    }
}
Q824 medium
What is the primary advantage of using a `try-with-resources` statement when working with `FileWriter`?
Q825 medium code output
What does this Java code print to the console?
java
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Set<Integer> numbers = new HashSet<>();
        numbers.add(10);
        numbers.add(20);
        numbers.add(10);
        numbers.add(30);
        System.out.println(numbers.size());
    }
}
Q826 medium
Which of the following best describes the condition required for an `if` statement's block of code to execute in Java?
Q827 medium
Under what condition does the Java compiler automatically provide a default no-argument constructor for a class?
Q828 hard code error
What will be the result of compiling this Java code?
java
abstract class Shape {
    abstract void draw();
    void fillColor() {
        System.out.println("Filling color");
    }
}
public class DrawingApp {
    public static void main(String[] args) {
        Shape s = new Shape(); // Problematic line
        s.fillColor();
    }
}
Q829 medium
Which of the following best describes the difference between `list.remove(Object o)` and `list.remove(int index)` for an `ArrayList`?
Q830 easy code output
What is the output of this Java code?
java
public class TypeCast {
    public static void main(String[] args) {
        int myInt = 100;
        double myDouble = myInt;
        System.out.println(myDouble);
    }
}
Q831 easy code output
What does this Java code print?
java
class Chain {
    Chain() {
        this(10);
        System.out.println("No-arg constructor");
    }
    Chain(int value) {
        System.out.println("Parameterized constructor with value: " + value);
    }
}
public class Main {
    public static void main(String[] args) {
        Chain c = new Chain();
    }
}
Q832 easy
Method overloading is an example of which type of polymorphism in Java?
Q833 hard
In a `try-with-resources` statement, if an exception is thrown both by the `try` block's execution and by the `close()` method of one of the resources, which exception is propagated and how is the other handled?
Q834 easy code output
What is the output of this code?
java
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        Map<String, Boolean> status = new HashMap<>();
        status.put("TaskA", true);
        status.put("TaskB", false);
        System.out.println(status.containsKey("TaskA") + ", " + status.containsKey("TaskC"));
    }
}
Q835 easy code error
What error occurs when `Thread.sleep()` is called with a negative argument?
java
public class Main {
    public static void main(String[] args) {
        try {
            Thread.sleep(-100); // Negative sleep time
        } catch (InterruptedException e) {
            System.out.println("Interrupted!");
        }
    }
}
Q836 easy
Which keyword is used to immediately terminate a `for` loop and continue program execution at the statement immediately following the loop?
Q837 medium
What is the primary purpose of using a labeled `break` statement in Java?
Q838 hard code error
What compile-time error will this Java code produce?
java
public class OperatorError10 {
    public static void main(String[] args) {
        final int counter = 10;
        counter++; // Error line
        System.out.println(counter);
    }
}
Q839 easy code error
What will be the result of executing the following Java code snippet?
java
import java.util.Queue;
import java.util.LinkedList;

public class QueueError {
    public static void main(String[] args) {
        Queue<Integer> numbers = new LinkedList<>();
        System.out.println(numbers.element());
    }
}
Q840 medium code output
What is the output of this code?
java
String raw = "   Hello World   ";
String trimmed = raw.trim();
System.out.println(raw.length() + " " + trimmed.length());
← Prev 4041424344 Next → Page 42 of 200 · 3994 questions