☕ Java MCQ Questions – Page 39

Questions 761–780 of 3994 total — Java interview practice

▶ Practice All Java Questions
Q761 easy
What types of methods can an abstract class in Java contain?
Q762 hard
Which statement regarding explicit constructor invocation using `this()` and `super()` is *false*?
Q763 easy
Is `ArrayList` synchronized (thread-safe) by default?
Q764 medium
Which of the following is the most modern and recommended way to ensure a `FileReader` is closed automatically, even if exceptions occur?
Q765 hard
Under what condition is an object's constructor NOT invoked during its creation process?
Q766 hard code error
What is the result of compiling and running the following Java code snippet?
java
public class StringError {
    public static void main(String[] args) {
        String value = "hello";
        String formatted = String.format("The number is: %d", value);
        System.out.println(formatted);
    }
}
Q767 easy
How does a HashMap determine if two keys are equal?
Q768 medium code error
What will be printed to the console when the following code is executed, assuming 'nonexistent.txt' does not exist?
java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class TestClass {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new FileReader("nonexistent.txt"));
            br.readLine();
            br.close();
        } catch (IOException e) {
            System.err.println("Caught exception: " + e.getClass().getSimpleName());
        }
    }
}
Q769 medium code error
What compile-time error will occur in this Java code snippet?
java
public class LoopError {
    public static void main(String[] args) {
        int limit = 5;
        for (int i = 0; i < limit; i++) {
            System.out.println(j);
        }
    }
}
Q770 easy code output
What is the output of this code?
java
import java.util.LinkedList;
import java.util.Queue;

public class Main {
    public static void main(String[] args) {
        Queue<String> messages = new LinkedList<>();
        messages.offer("Hello");
        messages.offer("World");
        messages.poll();
        System.out.println(messages.isEmpty());
    }
}
Q771 medium
Which method is the most idiomatic and often most efficient way to check if a `String` contains a specific sequence of characters in Java?
Q772 medium code output
What is the result when running the following Java code?
java
import java.io.BufferedWriter;
import java.io.StringWriter;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        StringWriter sw = new StringWriter();
        BufferedWriter bw = new BufferedWriter(sw);
        bw.write("Initial content");
        bw.close();
        try {
            bw.write("Attempting to write after close");
        } catch (IOException e) {
            System.out.print(e.getMessage());
        }
    }
}
Q773 easy code error
What is the error in the following Java code?
java
import java.util.TreeSet;
import java.util.Comparator;

public class Main {
    public static void main(String[] args) {
        TreeSet<String> set = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        set.add("Apple");
        set.add("Banana");
        set.remove(123);
    }
}
Q774 hard
What happens if a `finally` block executes a `return` statement after an exception has been thrown in the `try` block and caught in a `catch` block, or is pending propagation?
Q775 hard
Under which set of circumstances is a `finally` block NOT guaranteed to execute in Java?
Q776 medium
`BufferedWriter` is an example of which common object-oriented design pattern?
Q777 easy
When you perform an operation that seems to modify a `String` object (e.g., `str.toUpperCase()`), what actually happens?
Q778 easy
What must be true about the method signature (name and parameters) for a method to correctly override a superclass method?
Q779 medium code error
What error will this Java code produce when executed?
java
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<String> original = new ArrayList<>();
        original.add("A");
        List<String> unmodifiableList = Collections.unmodifiableList(original);
        Iterator<String> it = unmodifiableList.iterator();
        if (it.hasNext()) {
            it.next();
            it.remove(); // Attempt to remove from an unmodifiable list
        }
    }
}
Q780 easy code error
What compilation error will occur when compiling this Java code?
java
// No import for java.io.BufferedReader;

public class MyClass {
    public static void main(String[] args) {
        BufferedReader br;
    }
}
← Prev 3738394041 Next → Page 39 of 200 · 3994 questions