In Java, when a subclass has the same method as declared in the parent class, it is known as method ________.
- hiding
- inheriting
- overloading
- overriding
When a subclass has the same method name, return type, and parameters as declared in the parent class, it is known as method overriding. The subclass provides a specific implementation for that method.
Consider a scenario where two threads are trying to access synchronized methods in a single class instance. Describe how the synchronized methods will manage the access of these two threads.
- Both threads can execute the synchronized methods concurrently, as synchronization allows multiple threads to access synchronized methods simultaneously.
- The first thread will execute the synchronized method, and the second thread will wait until the first thread completes its execution.
- The second thread will execute the synchronized method and then the first thread, as the order of execution is undefined.
- The second thread will execute the synchronized method if it has a higher priority than the first thread.
Synchronized methods in a single class instance are mutually exclusive. Only one thread can execute a synchronized method at a time. The first thread to enter the synchronized method will execute it, and the second thread will wait until the first one completes its execution. The order of execution is not defined, and thread priority does not affect synchronization.
The ______ method of the Animation class is used to play the animation in reverse order from the end position.
- playBackward()
- reverse()
- reverseOrder()
- rewind()
To play an animation in reverse order from the end position in JavaFX, you can use the reverse() method of the Animation class. This method reverses the animation, making it appear as if it's playing backward. The other options do not specifically address reversing animations.
The ________ data type in Java can store decimal numbers up to 15 decimal places.
- BigDecimal
- double
- float
- long
In Java, the BigDecimal data type is used to store decimal numbers with precision up to 15 decimal places. It is commonly used in financial and scientific applications where high precision is required. The float and double types have limited precision and are not suitable for this purpose.
Externalizable interface extends ______ interface and adds two methods into it.
- Cloneable
- Externalization
- ObjectInput/Output
- Serializable
The Externalizable interface in Java extends the ObjectInput and ObjectOutput interfaces and adds two methods into it: writeExternal and readExternal. These methods are used for customized serialization of objects. The other options are not related to the Externalizable interface.
In which version of Java were Lambda expressions introduced?
- Java 6
- Java 7
- Java 8
- Java 9
Lambda expressions were introduced in Java 8. They are a significant feature that simplifies the syntax for writing anonymous functions and enhances the readability and conciseness of code in Java.
The ________ class represents a Uniform Resource Identifier and is designed to handle the complete URI syntax.
- URI
- URL
- URN
- UniformResource
The correct answer is "URI." In Java, the URI class is used to represent a Uniform Resource Identifier. It's designed to handle the complete URI syntax, including components like scheme, authority, path, query, and fragment. A URI is a broader concept that includes URLs (Uniform Resource Locators) and URNs (Uniform Resource Names).
The ________ method of the ExecutorService interface is commonly used to submit a Callable task and returns a Future object.
- execute
- invokeAll
- start
- submit
In Java, the submit method of the ExecutorService interface is used to submit a Callable task and returns a Future object representing the result of the computation. This method is commonly used for asynchronous tasks that return results.
A constructor in Java cannot have a return type and is declared with the same name as the ________.
- class
- interface
- method
- object
In Java, constructors are special methods used to initialize objects. They have the same name as the class they belong to, making option 1 ("class") the correct choice. Constructors cannot have a return type.
The ______ arithmetic operator divides the left-hand operand by the right-hand operand and returns the remainder.
- %
- *
- +
- -
The "%" (modulo) operator in Java is used to divide the left-hand operand by the right-hand operand and returns the remainder. For example, "10 % 3" returns 1 because 10 divided by 3 leaves a remainder of 1. The other operators perform different arithmetic operations.