By using the keyword ________, a subclass can call a method defined in its superclass.

  • extends
  • inherit
  • override
  • super
In Java, the keyword used to call a method defined in the superclass from a subclass is super. It's commonly used to access overridden methods or constructors in the parent class.

How can a developer prevent a field from being serialized?

  • Mark the field as final.
  • Mark the field as private.
  • Mark the field as static.
  • Mark the field as transient.
In Java, to prevent a field from being serialized, you can mark it as transient. When a field is marked as transient, it will not be included in the serialization process. The other options do not directly prevent serialization. Marking a field as final has no impact on serialization. Marking it as static means the field will be serialized. Marking it as private affects only access, not serialization.

Which method in the ExecutorService interface waits for all tasks to complete after a shutdown request?

  • awaitShutdown()
  • awaitTermination()
  • isTerminated()
  • shutdownNow()
The awaitTermination() method in the ExecutorService interface is used to wait for all tasks to complete after a shutdown request has been made using the shutdown() method. It blocks until all tasks have completed or the specified timeout has passed. The isTerminated() method checks if the ExecutorService has terminated but doesn't wait.

Which of the following states is not a valid thread state in Java?

  • Blocked
  • Running
  • Sleeping
  • Terminated
In Java, the valid thread states are Running, Blocked, Terminated, and Sleeping. "Running" is not a valid thread state because it's not used to describe the state of a thread in Java. A running thread is simply a thread that is currently executing its code.

Which of the following statements about constructor overloading in Java is correct?

  • Constructor overloading allows a class to have multiple constructors with the same name but different parameters.
  • Constructor overloading is not supported in Java.
  • Constructor overloading requires that all constructors have the same number of parameters.
  • Constructor overloading can only be used in abstract classes.
a) is correct. Constructor overloading in Java enables a class to have multiple constructors with the same name but different parameters. This allows for creating objects with various initializations. b) and d) are incorrect statements. c) is also incorrect because the number of parameters can vary among overloaded constructors.

In Java, which of the following statements is true regarding the fall-through behavior in the switch case?

  • In Java, when a case statement is matched, execution continues with the next case statement unless terminated by a break or other control flow statement.
  • The fall-through behavior is controlled by the continue keyword.
  • The fall-through behavior is controlled by the fallthrough keyword.
  • The fall-through behavior is not supported in Java switch cases.
In Java, the switch statement supports fall-through behavior, meaning that when a case label is matched, the code will continue to execute the subsequent case labels unless interrupted by a break statement. This behavior allows multiple cases to be executed for a single condition match, making it important to use break to terminate the flow when needed.

Which of the following is a valid synchronized method declaration?

  • public synchronized void myMethod() {}
  • public void myMethod() { synchronized() {} }
  • public void synchronized myMethod() {}
  • synchronized void myMethod() {}
The correct syntax for a synchronized method declaration in Java is public synchronized void myMethod() {}, where the synchronized keyword comes before the access modifier (public) and the return type (void). This ensures that only one thread can execute the myMethod at a time.

Which class is used to create a server-side socket that waits for client requests?

  • Server
  • ServerSocket
  • SocketListener
  • SocketServer
In Java, the ServerSocket class is used to create a server-side socket that listens for incoming client requests. It's an essential part of building network servers. The other options do not represent the correct class for this purpose.

In which scenario is a Do-While loop most appropriately used as compared to other loop structures?

  • When you know the exact number of iterations required.
  • When you need a loop with a fixed number of iterations.
  • When you need to execute the loop body at least once.
  • When you want to iterate through a collection.
A do-while loop is most appropriate when you need to execute the loop body at least once, regardless of the condition. It is useful when you want to ensure that a certain part of your code runs before checking the loop condition. This is different from other loop structures like for and while, where the loop body may not execute if the initial condition is false.

Which of the following is a valid constructor declaration in Java?

  • MyConstructor() {}
  • public MyConstructor() {}
  • public int MyConstructor() {}
  • void MyConstructor() {}
In Java, a valid constructor declaration doesn't specify a return type, and its name should match the class name. So, MyConstructor() {} is a valid constructor declaration. The other options are invalid because they specify a return type or access modifier.

When using a PreparedStatement, how is a value assigned to a placeholder?

  • By calling a separate method named "setValue"
  • Placeholder values are automatically assigned
  • Using the "=" operator
  • setXXX() methods (e.g., setString(), setInt())
In a PreparedStatement, values are assigned to placeholders using the setXXX() methods, where "XXX" represents the data type (e.g., setString() for strings, setInt() for integers). This ensures proper handling of data types and helps prevent SQL injection. The other options are not valid ways to assign values to placeholders.

The switch case in Java can be used with data types like _______, _______, and _______.

  • byte, short, int
  • char, long, byte
  • double, string
  • int, float, boolean
In Java, the switch case can be used with data types like char, long, and byte. While other data types like int, float, boolean, double, and String are commonly used in Java, they are not directly compatible with the switch case. This limitation is important to consider when using switch statements.