Java MCQs (Multiple Choice Questions) with Answers - Set III

Java MCQs ( Multiple Choice Questions ) with Answers - Set III - CodingHumans

Set III is the last of the three and goes a little deeper: the Object class, interfaces, exceptions, JDBC and JSP, plus a StringBuffer output question to finish. These come up a lot in second-year Java exams and in the MCQ round of service-company placements.

A few questions mention applets. Applets have been deprecated since Java 9 and no modern browser runs them, but older university syllabi still include them, so we have kept them and said so in the explanation.

How to use this set: pick an option for each question. You will see straight away whether it is right, with a short note on why. There are 15 questions.

What this set covers

  • java.lang.Object and the main method
  • Variable declarations and keywords
  • JDBC: executeUpdate and PreparedStatement
  • Interfaces and marker interfaces
  • The Throwable hierarchy
  • JSP, applets and the String/StringBuffer classes

Java MCQs with answers and explanations

Q1. All Java classes are derived from:

a) java.awt.Window

b) java.lang.Object

c) java.lang.Class

d) java.util.Name

Q2. What happens if you leave out String[] args from the main method?

a) The program exits after printing

b) Compilation error

c) It compiles, but the program will not start

d) No error, it runs normally

Q3. Which of these is NOT required in a variable declaration?

a) An assignment

b) An identifier

c) A data type

d) A semicolon

Q4. Which JDBC method should you use to run a DELETE query?

a) executeDelete()

b) executeUpdate()

c) executeDeleteQuery()

d) executeQuery()

Q5. True or false? i) AWT is an extended version of Swing. ii) The paint() method of the Applet class cannot be overridden.

a) i false, ii false

b) i true, ii false

c) i true, ii true

d) i false, ii true

Q6. Which method does the browser call first when it loads a new applet?

a) destroy()

b) main()

c) execute()

d) init()

Q7. A PreparedStatement object in JDBC is used to run ________ queries.

a) Executable

b) Simple

c) High-level

d) Parameterized

Q8. When a class implements an interface, it must provide a body for:

a) Two methods of the interface

b) Only some methods of the interface

c) All abstract methods of the interface

d) Any methods in the class

Q9. What do you need in order to run JSP pages?

a) A Java web server or servlet container

b) A mail server

c) A database connection

d) An applet viewer

Q10. Which JDK tool generates HTML documentation from the comments in your source code?

a) javap

b) jar

c) jdb

d) javadoc

Q11. An interface with no fields or methods is known as a:

a) Abstract interface

b) Marker interface

c) CharSequence interface

d) Runnable interface

Q12. Which classes are the direct subclasses of Throwable?

a) Exception and VirtualMachineError

b) Error and Exception

c) RuntimeException and Error

d) IOException and VirtualMachineError

Q13. Where is a String stored when you create it with the new operator?

a) Heap memory

b) String memory

c) Random storage space

d) Stack

Q14. Which of these is a reserved keyword in Java?

a) object

b) system

c) main

d) strictfp

Q15. What does this program print?

public class Test2 {
    public static void main(String[] args) {
        StringBuffer s1 = new StringBuffer("Complete");
        s1.setCharAt(1, 'i');
        s1.setCharAt(7, 'd');
        System.out.println(s1);
    }
}

a) Cimpletd

b) Coipletd

c) Iomplede

d) Complete

Quick revision notes

  • Every class extends java.lang.Object unless it extends something else.
  • JDBC: executeQuery for SELECT, executeUpdate for INSERT/UPDATE/DELETE, execute when you are not sure.
  • PreparedStatement uses ? placeholders and helps stop SQL injection.
  • Throwable → Error and Exception; Exception → checked exceptions and RuntimeException.
  • Strings are immutable; StringBuffer (thread-safe) and StringBuilder (faster) can be changed in place.

Frequently asked questions

Should I still study applets?

Only if your syllabus asks for them. They are deprecated and no browser supports them. For real projects, learn JavaFX or a web framework like Spring Boot instead.

What is the difference between StringBuffer and StringBuilder?

Both are mutable. StringBuffer methods are synchronized, so it is safe across threads but slower. StringBuilder is the usual choice in single-threaded code.

Where can I find more Java practice?

Go back to Set I and Set II if you skipped them, then try our Core Java important questions and the Java Collections interview questions.

Comments

Answered 0/0Correct 0