Basic Java Interview Questions
.jpg)
21. Question: What is the purpose of the 'interface' keyword in Java? Answer: The 'interface' keyword in Java is used to declare a collection of abstract methods that can be implemented by classes. It provides a way to achieve multiple inheritances and define a contract for implementing classes. 22. Question: How does the 'StringBuilder' class differ from 'StringBuffer' in Java? Answer: Both 'StringBuilder' and 'StringBuffer' are used for string manipulation, but 'StringBuilder' is not synchronized, making it more efficient in a single-threaded environment, whereas 'StringBuffer' is synchronized, ensuring thread safety in a multi-threaded environment. 23. Question: What is the purpose of the 'transient' keyword in Java? Answer: The 'transient' keyword in Java is used to indicate that a variable should not be serialized during object serialization. It is often used for sensitive informatio...