Which keyword is used to achieve runtime polymorphism? a. override b. extends c. final…
- User
Which keyword is used to achieve runtime polymorphism?
a. override
b. extends
c. final
d. super
- Assistant
The keyword used to achieve runtime polymorphism is:
a. override
This keyword is used in a subclass to indicate that the method is intended to override a method declared in a superclass. It ensures that the method is overriding a method from the superclass, thus playing a crucial role in runtime polymorphism by allowing the method to be dynamically bound at runtime to the method of the subclass.
- User
Which of the following is an example of runtime polymorphism?
a. Using final keyword
b. Method overloading
c. Method overriding
d. Variable shadowing
- Assistant
The correct answer is:
c. Method overriding
Method overriding is a feature where a subclass has a specific implementation of a method that is already provided by its superclass. This is an example of runtime polymorphism because the method that gets executed is determined at runtime, depending on the object that invokes it. This allows multiple forms (different method implementations) to be handled at runtime.
- User
Which of the following is used to write primitive data types to a file?
a. PrintWriter
b. FileWriter
c. BufferedWriter
d. DataOutputStream
- Assistant
The correct answer is:
d. DataOutputStream
DataOutputStream is used to write primitive data types to an output stream in a portable way. This class allows an application to write Java primitive data types to an output stream in a machine-independent way, making it especially useful for writing data such as int, float, and double to files in a format that can be read back consistently.
- User
Which interface does SortedSet extend?
a. List
b. Collection
c. Set
d. Map
- Assistant
The correct answer is:
c. Set
The
SortedSetinterface in Java extends theSetinterface.SortedSetis a sub-interface ofSetthat provides a total ordering on its elements. This interface behaves like theSetinterface except that it guarantees that the elements are sorted either naturally or by a comparator provided at sorted set creation time.