Already Passed
What is the purpose of the instanceof operator in Java?
✔✔A) It checks if an object is an instance of a specific class or subclass
B) It converts an object to a superclass type
C) It prevents method overriding
D) It forces type conversion
Which statement about try-with-resources is correct?
✔✔A) It automatically closes resources like streams after execution
B) It allows catching multiple exceptions in one block
C) It prevents exceptions from occurring
D) It is required for handling runtime exceptions
Which access modifier makes a member accessible only within the same package?
✔✔A) Default (no modifier)
B) private
C) protected
1
,D) public
Which of the following is NOT a valid way to create a thread in Java?
A) Extending the Thread class
B) Implementing the Runnable interface
✔✔C) Declaring a method as synchronized
D) Using an ExecutorService
What will happen if a main() method is declared as private?
A) The program will run normally
B) It will execute without errors
✔✔C) The program will not compile
D) The JVM will ignore the method
Which of the following is true about Java Reflection?
✔✔A) It allows inspection and modification of class members at runtime
B) It improves program performance
C) It is used only for debugging
2
, D) It can access private members without restrictions
What happens if you try to override a static method?
A) The method is inherited normally
B) A runtime error occurs
✔✔C) The method is hidden, not overridden
D) The method is converted into an instance method
Which of the following best describes a marker interface?
A) An interface with only private methods
✔✔B) An interface with no methods or fields
C) An interface used for debugging
D) An interface that must be implemented by all classes
What is the main purpose of the final keyword in Java?
A) To define a loop
B) To allow a class to be extended
✔✔C) To prevent modification of variables, methods, or classes
3