Java Practice Tests – 1 1. Java Practice Tests How do == and equals() differ in Java? == checks for reference equality, while equals() checks for logical equality. == checks for logical equality, while equals() checks for reference equality. == and equals() are equivalent. == is for primitive types, while equals() is for objects. None 2. Java Practice Tests What does the default keyword do in Java interfaces? It provides default implementations for methods in an interface. It marks an interface as default. It prevents an interface from being implemented. It specifies a default method of a class. None 3. Java Practice Tests What does the synchronized keyword do in Java? It ensures that only one thread can access a block of code at a time. It makes a method thread-safe without using locks. It allows multiple threads to access a block of code simultaneously. It guarantees the order of execution in a multi-threaded environment. None 4. Java Practice Tests What is the purpose of the transient keyword in Java? To exclude a field from serialization. To include a field in serialization. To mark a method as transient. To make a field eligible for garbage collection. None 5. Java Practice Tests What function does the volatile keyword serve in Java? It ensures that updates to a variable are visible across threads. It makes a variable thread-safe. It guarantees atomicity of operations. It prevents concurrent modifications to a variable. None 6. Java Practice Tests Which statement about the final keyword is accurate? final can be applied to classes, methods, and variables. A final class can be inherited. A final method can be overridden. A final variable cannot be initialized after declaration. None 7. Java Practice Tests Which statement about Java exception handling is correct? Checked exceptions must be handled or declared in the method signature. Runtime exceptions must be caught or declared in the method signature. Errors are considered as checked exceptions. RuntimeException is a checked exception. None 8. Java Practice Tests What does the super keyword do in Java? It refers to the superclass of the current object. It creates a new instance of the superclass. It modifies the superclass. It prevents method overriding. None 9. Java Practice Tests Which of the following is not a valid access modifier for methods in Java? private protected default internal None 10. Java Practice Tests Which of these statements is true about Java interfaces? Interfaces can extend other interfaces. Interfaces can implement other interfaces. Interfaces can have constructors. Interfaces can have non-static nested classes only. None Time's up